tags:

views:

43

answers:

4

Hi All,

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

A: 

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.

matpol
$('.banner-textarea'), since its a class not id :P
Wai Wong
+1  A: 

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.

jAndy
A: 

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);
Michael Lumbroso
+1  A: 

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

RobertPitt
This should definately be flagged as the answer.
CeejeeB
Flagged ? What for!
RobertPitt
Sorry not flagged as in reported for being offensive. The correct word probably should have been 'marked' as the answer
CeejeeB
As a side note where can I find documentation about the second param overload?
CeejeeB
Posted it in the OP, Theres not alot of documentation on this just shows one example of using root document[0] but as you can see in the version history in 1.0 it shows you *jQuery( selector, [ context ] )* and *contextA DOM Element, Document, or jQuery to use as context*
RobertPitt