The one I'm talking about is one where I have the code appear literally, a string. How do I combine it with actual code, like <div id="thing">string goes here</div>
?
I've tried making the div and id part of the content inside the (' ')
but it doesn't work. When I do that, the content never gets appended.
Here's the code:
$('#placeToAppendTo').append
('<br><div><input type="text" class="textfield" id="text'+textClicked+'"</div>');
To get the HTML you presented, you would do something like this:
var elem = document.createElement('div');
elem.id = "thing";
elem.appendChild(document.createTextNode("string goes here"));
I hope this helps, since your question isn't particularly clear.
或在jQuery中:
$('<div />', {id:'thing', text:'string goes here'});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.