Im trying to find a way to add a anchor tag to all h3 tag.The content is dynamic in nature .
I want to add dynamic anchor tag for all the h3 tags only
<div class="class1">
<h2>Main heading</h2>
<h3>Heading1</h3>
<h1>some content1</h1>
<h3>Heading2</h3>
<h1>some content2</h1>
<h3>Heading3</h3>
<h1>some content3</h1>
</div>
I tried below Jquery code but its creating nothing
$("h3.class1").append('<h3>');
var al = $("h3.class1 >");
al.append('<a href="#"></a>');
$('div.class1 h3').each(function (){
$(this).wrap('<a />');
});
Use wrap:
Wrap an HTML structure around each element in the set of matched elements.
$('.class1 h3').wrap('<a />');
This will wrap all the h3 inside .class1 by anchor tag.
DEMO
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