Creating a div element in jQuery does a good job on describing how to create and insert an element, however, I wish to create an element with a child element such as <li><a href="abc.html">click</a></li>. The href and text is susceptible to XSS, so I need take steps. I could create the <a> element like:
var href='abc.html',text='click';
jQuery('<a/>', {
href: href,
text: text
}).appendTo('#mySelector');
How do I modify this to include the </li> element?
wrap it up:
$(document).ready(function() {
var href='abc.html',text='click';
jQuery('<a/>', {
href: href,
text: text
}).wrap("<li>").parent().appendTo('#mySelector');
})
http://codepen.io/anon/pen/Eyqco
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With