javascript - Select all previous elements within a container? -
i have code:
<div id="whatever"> <span>1</span> <span>2</span> <span>3</span> <span>4</span> </div> <div id="whatever2"> <span>1</span> <span>2</span> <span>3</span> <span>4</span> </div> and need select jquery previous spans 1 hover within same div.
does know how can this?
you can use prevall() achieve this.
prevall() - preceding siblings of each element in set of matched elements, optionally filtered selector.
here's jsfiddle example.
here's code example:
jquery:
$('span').hover(function(){ $(this).prevall().toggleclass('previous'); }); css:
.previous { color:red; }
Comments
Post a Comment