jquery - how to apply to avoid adding all .test classes from the page in the code $( ".test" ).insertBefore( ".test1" ) -


how apply avoid adding .test classes page in code

$( ".test" ).insertbefore( ".test1" )

<div id="testdiv"> <div class="test1"></div> <div class="test"></div> </div> 

div replicated on page

you need iterate on each test element , insert before previous sibling .test:

$(".test").each(function(){   $(this).insertbefore($(this).prev()); }) ; 

Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

unity3d - Fatal error- Monodevelop-Unity failed to start -