is there way assign nested div attribute variable?
<div> <div> 123456 </div> </div>
become
<div> <div sectionid="123"> 123456 </div> </div>
btw above component created javascript.
i've tried this, didn't work.
var = $('<div><div>123456</div></div>'); a.eq(":nth-child(2)").attr("sectionid", "123");
try snippet.
//for dom html console.log("for dom html"); //1st way $('#input > div').find('div').attr("sectionid","123"); console.log($('#input').html()); //2nd way $('#input > div > div').attr("sectionid","321"); console.log($('#input').html()); //js html console.log("for js object"); var input = $('<div><div>123456</div></div>'); //1st way input.eq(0).children().attr('sectionid', '456'); console.log(input[0].outerhtml); var input = $('<div><div>123456</div></div>'); //2nd way $(input[0]).children().attr('sectionid', '789'); console.log(input[0].outerhtml);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="input"> <div> <div> 123456 </div> </div> </div>
Comments
Post a Comment