tags:

views:

22

answers:

1

My code is below. I have a javacript function which for every html div with id equal to 'plus+id' changes the attribute and html. I want it to only change one div with required id (the next instance of the div after the jquery function code) on the page rather than all the divs above and below the jquery code. Is this possible?

$('#plus'+id+' .plus_bouton#favori').attr('OnClick',"AddToFav('delete','"+id+"');");
$('#plus'+id+' .plus_bouton#favori .label').html('{/literal}{$lang137}{literal}');
+1  A: 

use the :first selector

http://api.jquery.com/first-selector/

$('#plus' + id + ' .plus_bouton#favori:first').click(function() {
    AddToFav('delete', $(this).attr('id')); 
});

$('#plus' + id + ' .plus_bouton#favori:first .label').html('{/literal}{$lang137}{literal}');
hunter
Does that modify the first DIV with required ID AFTER those lines of JQuery code or does it modify the first DIV with required ID found in the entire code from the beginning? Because I want the former, not the latter.
David Willis
Right, `#plus' + id + ' .plus_bouton#favori:first"` would match the first element with css class `plus_bouton` AND id of `favori`
hunter
I want it to find the first such element after the above code. I don't want it to search from the beginning of the code and locate the first element, I want it to search from the point at which the Jquery code ends. And the element I wish to modify is the one with id "plusid" whatever id may be (id is an argument of the function) and also is of class plus_bouton. So that is what I am trying to do, please help if possible
David Willis