[英]Add a span in a span with JQuery
I'm trying to put a <span>
in an other <span>
in the title of JQuery's modal but it doesn't work. 我正在尝试在JQuery的模式标题中将
<span>
放在另一个<span>
中,但是它不起作用。
Here's my HTML code : 这是我的HTML代码:
<div class="ui-dialog-titlebar...">
<span class="ui-dialog-title">Info title</span>
...
</div>
<div id="1">
And I want to put a <span class="glyphicon glyphicon-info-sign"></span>
inside the ui-dialog-title
<span>
. 我想在
ui-dialog-title
<span>
内放置<span class="glyphicon glyphicon-info-sign"></span>
<span>
。
I tried to do it like this : 我试图这样做:
$(".ui-dialog-title").prepend('<span class="glyphicon glyphicon-info-sign"></span>');
And it 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 , I will have multiple <span>
with the class ui-dialog-title
in my document and I want to access this <span>
using the id of the next <div>
. 但是 ,我的文档中将有多个
<span>
带有ui-dialog-title
,并且我想使用下一个<div>
的ID访问此<span>
<div>
。
I tried this : 我尝试了这个:
$("#"+myId).prev("div").first("span").prepend('<span class="glyphicon glyphicon-info-sign"></span>');
But the glyphicon <span>
was placed BEFORE ui-dialog-title <span>
: 但是glyphicon
<span>
被放置在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 it is placed here because with the other method, it works. 我不明白为什么将其放置在这里,因为使用其他方法,它可以工作。
I hope you will understand my problem and thank you for your help ! 希望您能理解我的问题,并感谢您的帮助!
You can do: 你可以做:
$("#"+myId).prev("div").find(".ui-dialog-title").prepend('<span class="glyphicon glyphicon-info-sign"></span>');
Structure: 结构体:
<div class="ui-dialog-titlebar">
<span class="ui-dialog-title"><span class="glyphicon glyphicon-info-sign"></span>Info title</span>
</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.