.find css class in a jQuery variable for further manipulation
I have some html in a jQuery 开发者_高级运维variable
var banner = $("<div class='banner-textarea'></div>");
hot can i search "banner" and find banner-textarea so i can amend the html.
var LIs=ul.find("div.banner-textarea");
Above is not working!
Many thanks
You can search within your jQuery object
.
banner.find('.banner-textarea').ApplySomeFunctions();
Unfortunatly, you didn't show where ul
comes into play. You would need
var ul = $('<ul/>').append(banner)
to create such an object structure. That in turn, makes no sense obviously.
This is asimple, you dont need to use append or find just add the context as the 2nd param like so
var banner = $("<div class='banner-textarea'></div>");
var texta = $("div.banner-textarea",banner);
this will tell jQuery to search only within the walls of banner and not the whole document.
Cant belive non of you guys know this :/
http://api.jquery.com/jQuery/#jQuery1
I don't see why you would like to do this, if it doesn't exist in the html, why would you like to find it?
I think you are looking for append function : jQuery append()
$("#div_you_want_to_append_banner_in").append(banner);
I think you need to read the jquery docs.
$('#banner-textarea')
will find the element in question assuming that you have an element in the page with an id of banner-textarea.
精彩评论