如何使用javascript删除div中的元素?
我尝试删除div LOGDIR=/a/b/logdir
tr=`date +%p`
echo $tr
if [ $tr = "PM" ];
then
date=`date +%Y-%m-%d`
echo "considering today's date for grepping logs"
else
date=`date -d '1 day ago' +%Y-%m-%d`
echo "considering yesterday's date for grepping logs as job run is delayed"
fi
ITEM_FILE=/a/b/c/d/ids_`date +%d_%m_%Y_%H_%M_%S`.log
但不行,我该怎么做?
感谢所有人..
http://jsfiddle.net/tr8ack7v/1/
id="myList_2"
答案 0 :(得分:0)
你去了 - fiddle
不要在html元素上重用id
。 id
应该是唯一的,请改用class
。
var a = $('#myList_1 > .x');
$('button').click(function(){
$(a).remove();
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="myList_1">
<span class="x">111111</span>
</div>
<div id="myList_2">
<span class="x">222222</span>
</div>
<button>Try it</button>
&#13;
答案 1 :(得分:0)
在"x"
元素处重复id
span
个?请尝试分别将"1"
,"2"
添加到span
id
媒体资源,以替换文档中的唯一id
代替id
s span
1}}元素
<div id="myList_1">
<span id="x1">111111</span>
</div>
<div id="myList_2">
<span id="x2">222222</span>
</div>
<button onclick="myFunction(2)">Try it</button>
<script>
function myFunction(data_value) {
var list = document.getElementById("myList_" + data_value);
var x_child = document.getElementById("x" + data_value);
list.removeChild(x_child);
}
</script>
&#13;
答案 2 :(得分:0)
你有两个id
是相同的,id
应该是唯一的。
这是一个使用类的版本(不必是唯一的):
<div id="myList_1">
<span class="x">111111</span>
</div>
<div id="myList_2">
<span class="x">222222</span>
</div>
<button onclick="javascript: myFunction(2)">Try it</button>
<script>
function myFunction(data_value) {
var list = document.getElementById("myList_"+data_value);
var x_child=list.getElementsByClassName("x")[0];
list.removeChild(x_child);
}
</script>
答案 3 :(得分:0)
<div id="myList_1">
<span id="x1">111111</span>
</div>
<div id="myList_2">
<span id="x">222222</span>
</div>
<button onclick="myFunction(2)">Try it</button>
<script>
function myFunction(data_value) {
var list = document.getElementById("myList_"+data_value);
var x_child=document.getElementById("x");
list.find('#x').remove();
}
</script>