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 >