I have couple of divs like
<div id="rg_dia_0">
zdszczxvzxvzxvc
</div>
<div id="rg_dia_1">
dfgdZXcZC
</div>
<div id="rg_dia_2">
hfhgjhgjdj
</div>
I need javascript to fetch all th开发者_JAVA技巧e divs and delete the content. I think we can use regex to match the ids as only the number that is changing.
As said by Sam in Javascript it can be
for (var i = 0; i <= 2; i++) {
document.getElementById("rg_dia_" + i).innerHTML = "";
}
Something like this can easily be done with jQuery. I would strongly encourage you to learn it.
$('div').each(function() {
$(this).html('');
});
$('#id').html(newContent);
try:
$("div[id^='rg_dia_']").html("");
see this for wildcard attribute selection in jQuery.
for (var i = 0; i <= 2; i++) {
$("#rg_dia_" + i).html("");
}
to clarify; the above obviously requires the use of jQuery, as l.devries so blatantly down-voted as an act of true adulthood and surely not be considered as trolling since the explanation as of why had to be requested first. glad to have people like you on-board!
精彩评论