Javascript 从所有定位标记中删除图像标记
我有以下表格标题:Javascript 从所有定位标记中删除图像标记,javascript,jquery,html,Javascript,Jquery,Html,我有以下表格标题: <table id="time" class="new_table" border="0" cellpadding="2"> <thead> <tr> <th scope="col" rowspan="2" class="sortHead"> <a href="#" id="unitSort">Unit</a>
<table id="time" class="new_table" border="0" cellpadding="2">
<thead>
<tr>
<th scope="col" rowspan="2" class="sortHead">
<a href="#" id="unitSort">Unit</a>
</th>
<th colspan="2" id="startDateHead" class="sortHead">
<a href="#" id="startDateSort">Start</a>
</th>
<th colspan="2" id="endDateHead" class="sortHead">
<a href="#" id="endDateSort">End</a>
</th>
<th rowspan="2" class="sortHead">
<a href="#" id="distanceSort">Distance (miles)</a>
</th>
<th rowspan="2" class="sortHead">
<a href="#" id="locationSort">Location</a>
</th>
<th rowspan="2" class="sortHead">
<a href="#" id="driverName">Driver Name</a>
</th>
</tr>
添加到a标记的img元素示例如下:
<a href="#" id="driverName">Driver Name<img id="test" src="test.png" width="10"></a>
当发生以下情况时,如何删除此表a标记中的所有img标记
他们在那里
简单地
$('#time th a img').remove();
如果稍微翻转一下语法,您的尝试就会起作用。我无法解释为什么你的版本不起作用。表明它应该
$('#time th a').each(function() {
$(this).find('img').remove();
});
我稍微修改了您的代码,添加了
。找到(“img”)
然后使用.remove()
$('#time th')。每个(函数(){
$(this.find(“img”).remove();
});代码>
$('#time th a').each(function() {
$(this).find('img').remove();
});