jquery script

droctoganapus86

New Member
Messages
49
Reaction score
0
Points
0
I am trying to make a script with jquery. The function is to add an additional <li> to an <ul>
I have lots of <ul>'s, and i want to target a specific one. How is the best way to do this?

I have this (simpliefied) html. The target <ul> is the one coming right after the "links" div
Code:
<div class="clear">
	<div class="links">
		<button type="button" class="makecomment">Comment</button>
	</div>
	<ul>
		<li class="arrow">&nbsp;</li>
		<li class="comment"></li>
	</ul>
</div>
... and that a couple o'times
and this code :
Code:
$('button.makecomment').click(function(){
	$('<li class="comment"></li>').hide().appendTo('').fadeIn('slow');
});
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
It depends on the best way to relate the button to the list. If you're generating the HTML, you could use an ID selector. Alternatively, if the button and the list have the same relative position in the document structure, you could traverse the document:

Code:
$('.makecomment').live('click', 
    function (evt) {
        var comments = $(this).closest('.links').nextAll('ul').first();
        ...
    });
 
Top