我制作了一些代码宽度 jquery 我的目标是在 #pivot 和上面 <li><a href="#">bottom</a></li>
下添加列表怎么办??
当我像这样尝试时,唯一的 <li><a href="#"></a></li>
添加不带文本“新行”
请教我
HTML
<li><a href="#">top</a></li>
<li id="pivot"><a href="#">Pivot</a></li>
<li><a href="#">bottom</a></li>
Javascript
var dom = '<li><a href="#"></a></li>';
$('a',dom).text('new row');
$('#pivot').after(dom);
最佳答案
那是因为您正在从字符串创建 jQuery 对象,但不存储/使用创建的元素。
$(dom) // parse the string and create a jQuery object
.find('a') // find the `a` descendants
.text('new row') // update their textContent
.end() // get the previous jQuery collection
.insertAfter('#pivot'); // insert the collection after `#pivot` element
关于javascript - JQUERY 更改父元素中子元素的文本或值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27589965/