Friday, 15 February 2013

jquery - Split 1 div into 2 separate div's? -



jquery - Split 1 div into 2 separate div's? -

is possible jquery split 1 div 2 div's @ specified point marked tag

in code illustration thinking possible split div @ 'em tag' create 2 div's

<div> <p>lorem ipsum dolor sit down amet, consectetur adipisicing elit,</p> <em></em> <p>lorem ipsum dolor sit down amet, consectetur adipisicing elit,</p> </div>

to

<div> <p>lorem ipsum dolor sit down amet, consectetur adipisicing elit,</p> </div> <div> <p>lorem ipsum dolor sit down amet, consectetur adipisicing elit,</p> </div>

you can utilize next code resolve issue. assign id parent div , remove html after preserving inner html. can remove parent div after storing html in variable dont because have place modified html on same place.

var divhtml = $("#divid").html(); var myps = divhtml.split("<em></em>"); var myhtml = "<div>"+myps[0]+"</div><div>"+myps[1]+"</div>"; $("#divid").html(myhtml);

if must remove parent tag can lastly element id, remove main div after storing html in variable , place modified html next after lastly element.

jquery

No comments:

Post a Comment