Writing Html With Jquery
I am new to jQuery. I want to write the following HTML (along with the classes) using jQuery. How can I do this?
hi how are yo
Solution 1:
$('<div>').addClass('phnbr').append($('<div>').addClass('phtext').append('hi how are you, ').append($('<a>').attr({ target: '_blank', href: 'http://www.xyc.com'}).text('click here.')));
Solution 2:
$('<div class="phnbr"> \
<div class="phtext">hi how are you, <a target="_blank" href="http://www.xyz.com">click here.</a> \
</div> \
</div>'); // bang done!
Solution 3:
Well you can just use append() or the other DOM Insertion Functions
$(document.body).append('<div class="phnbr"><div class="phtext">hi how are you, <a target="_blank" href="http://www.xyz.com">click here.</a></div></div>');
Post a Comment for "Writing Html With Jquery"