I know how to create elements with jquery using something like:
$('<div/>').appendTo('body');
How can I create this:
<a href=""><img src="" /></a>
Using the same technique?
$('<a href=""><img src="" /></a>'). appendTo('body'); or $('<a href=""></a>'). append('<img src="" />').
You can now link to this section (div) using the anchor tag. To do that, just use the id of the section with a # as the prefix for the href value.
$('<img />').attr({
src:'some image url',
width:'width in intiger',
height:'integer'
}).appendTo($('<a />').attr({
href:'somelink'
}).appendTo($('#someElement')));
You can first select the html element using jquery and then use the "html()" method to set the desired html. Here is a sample:
$('div.demo-container')
.html('<a href=""><img src="" /></a>');
The only thing is that you should be able to uniquely identify the desired div that you want to alter. Probably by setting id or class.
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