If I have a variable defined in jquery as follows:
var insertString = "<div id='divid'>";
insertString += "<input type='text' name='textbox' value=''>";
insertString += "</div>";
Now, if I want to insert the above variable ‘insertString’ before some DOM element, how can I do it? I tried Something like below with no success
insertString.insertBefore("body");
You should be able to wrap your html in a
$()function thus passing it to jQuery and creating a jquery object. Then you can operate on that object by chaining jQuery functions like this:But it would be pretty weird to put a div BEFORE the body… maybe it is better to prepend it to the body like this…