Using before method in jquery

To add an html element or some text right before an html element we use before method of jquery. This will add the given element/text right before the element which we are targeting.

<input type="button" value=" Add Before Div " onclick="AddBeforeDiv()" />
<div id="myDiv" class="myClass">
    This is a div
</div>

<script type="text/javascript">
   function AddBeforeDiv () {
        $("#myDiv").before("<span>This is appended before div</span>");
    };
</script>

Comments

Popular posts from this blog

Check if ViewBag is null or doesn't exist

Using Progress Bar In C#

Jquery serer side datatables in asp.net