Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select appended item jquery

Tags:

How would i select the below item, i do not want to select every LI of .top but just the LI i have just created on the append.

How is this possible?

$('.top').append('<li><span>' + html + '</span></li>'); 
like image 402
Xavier Avatar asked Sep 08 '11 14:09

Xavier


People also ask

How do I select a specific Dropdownlist using jQuery?

Syntax of jQuery Select Option$(“selector option: selected”); The jQuery select option is used to display selected content in the option tag. text syntax is below: var variableValue = $(“selector option: selected”).

What is append in jQuery?

jQuery append() Method The append() method inserts specified content at the end of the selected elements. Tip: To insert content at the beginning of the selected elements, use the prepend() method.

How append a div in another div using jQuery?

The . append() method inserts the specified content as the last child of each element in the jQuery collection (To insert it as the first child, use . prepend() ).

How do you use .append in JS?

1) Using the append() method to append an element example First, select the ul element by its id by using the querySelector() method. Second, declare an array of languages. Third, for each language, create a new li element with the textContent is assigned to the language.


1 Answers

You could do it the other way around using appendTo()

var li = $('<li><span>' + html + '</span></li>').appendTo('.top'); 

This way you don't have to select it after appending it.

like image 59
Richard Dalton Avatar answered Nov 15 '22 16:11

Richard Dalton