Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
168
rated 0 times [  174] [ 6]  / answers: 1 / hits: 38420  / 14 Years ago, tue, november 2, 2010, 12:00:00

I have a list of spans with particular class place and some of them have class activated. Is there a way to select the first item with class activated and the last?



<span class=place onclick=activate();>1</span>
<span class=place onclick=activate();>2</span>
<span class=place activated onclick=activate()>3</span>
<span class=place activated onclick=activate();>4</span>
<span class=place activated onclick=activate();>5</span>
<span class=place activated onclick=activate();>6</span>
<span class=place onclick=activate();>7</span>

More From » jquery

 Answers
0
var firstspan = $('span.activated:first'),
lastspan = $('span.activated:last');


By the way, if you're using jQuery, what's with all the inline click events?



You could add some code like so:



$('span.place').click(function() {
activate(); // you can add `this` as a parameter
// to activate if you need scope.
});

[#95101] Saturday, October 30, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
lailab

Total Points: 706
Total Questions: 102
Total Answers: 95

Location: Falkland Islands
Member since Mon, Jul 13, 2020
4 Years ago
;