I'm completely new to jQuery. To be honest it is my first few days.
And there is my first question.
$(document).ready(function() {
$('span.head-span').parent().addClass('head-h').append('<div class="clx" />')
});
As a result I have this
<h1 class="head-h"><span class="head-span">This is Some Heading</span><div class="clx"/></h1>
What do I need to do in jQuery so my .clx will appear after . like this
<h1 class="head-h"><span class="head-span">This is Some Heading</span></h1><div class="clx"/>
Thank you very much in advance.
The . append insert the parameter element inside the selector element's tag at the last index position, whereas the . after puts the parameter element after the matched element's tag.
append( function ) A function that returns an HTML string, DOM element(s), text node(s), or jQuery object to insert at the end of each element in the set of matched elements.
To append using the innerHTML attribute, first select the element (div) where you want to append the code. Then, add the code enclosed as strings using the += operator on innerHTML.
You should be able to do this using after()
instead of append()
$('span.head-span').parent().addClass('head-h').after('<div class="clx" />')
If you want the div after the header, don't append it, use the after
method:
$('h1').after('<div class="clx" />');
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