javascript - Add a span in a span with JQuery -


i'm trying put <span> in other <span> in title of jquery's modal doesn't work.

here's html code :

<div class="ui-dialog-titlebar...">   <span class="ui-dialog-title">info title</span>   ... </div> <div id="1"> 

and want put <span class="glyphicon glyphicon-info-sign"></span> inside ui-dialog-title <span>.

i tried :

$(".ui-dialog-title").prepend('<span class="glyphicon glyphicon-info-sign"></span>'); 

and works !

<div class="ui-dialog-titlebar...">   <span class="ui-dialog-title">     <span class="glyphicon glyphicon-info-sign"></span>info title   </span>   ... </div> <div id="1"> 

but, have multiple <span> class ui-dialog-title in document , want access <span> using id of next <div>.

i tried :

$("#"+myid).prev("div").first("span").prepend('<span class="glyphicon glyphicon-info-sign"></span>');

but glyphicon <span> placed before ui-dialog-title <span> :

<div class="ui-dialog-titlebar...">   <span class="glyphicon glyphicon-info-sign"></span>   <span class="ui-dialog-title">info title</span>   ... </div> <div id="1"> 

i don't understand why placed here because other method, works.

i hope understand problem , thank !

you can do:

$("#"+myid).prev("div").find(".ui-dialog-title").prepend('<span class="glyphicon glyphicon-info-sign"></span>'); 

working example

structure:

<div class="ui-dialog-titlebar">   <span class="ui-dialog-title"><span class="glyphicon glyphicon-info-sign"></span>info title</span>  </div> 

Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -