Reputation: 1079
I want to add html tag without ending tag like that <div class="bottom-widget">
. For that I use jQuery prepend() method but full tag was added by this !
Html Markup -
<div class="widget">
<h2>this is content 1</h2>
</div>
</div>
Javascript Code :
$(".widget").prepend('<div class="bottom-widget">');
Upvotes: 1
Views: 103
Reputation: 237
I assume you need correct html so after this opening tag you will have another with closing one. For this reason you can use jQuery wrapInner
function (http://api.jquery.com/wrapinner/)
First extract(or create) the element you want to be wrapped in your bottom-widget element, than create bottom-widget element and insert above-mentioned element into it.
Upvotes: 1
Reputation: 15593
Perhaps you are looking for wrapInner
function.
And you code will be:
$(".wrapInner").wrapInner("<div class='bottom-widget'>");
Upvotes: 1
Reputation:
$(".widget").prepend("<div class='bottom-widget'></div>");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="widget">
<h2>this is content 1</h2>
</div>
Upvotes: 0