使用指定的ID隐藏元素 [英] Hiding elements with a specified id
本文介绍了使用指定的ID隐藏元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个不同的div
I have two different divs
var promptContent = $('<div id="errorr">').addClass("formErrorContent").html(promptText).appendTo(prompt);
var arrow = $('<div id="errorrarrow">').addClass("formErrorArrow");
我想在javascript中使用它们的id,像这样
I want to use their id in javascript like this
function windowclose()
{
document.getElementById('add_project').style.display="none";
document.getElementById('blanket').style.display="none";
document.getElementById('errorr').style.display="none";
document.getElementById('errorrarrow').style.display="none";
// $("#blanket").fadeIn("none");
// $("#add_project").fadeIn("none");
}
但是这里只隐藏第一个div。我想隐藏所有具有相同ID的div。我怎么做到这一点?
But here it hides only the 1st div. I want to hide all the divs with the same id. How can I do this?
推荐答案
尽管在许多元素上使用相同的ID在语义上是无效的,但您可以在单个jQuery行。
Even though using the same ID on many elements is semantically invalid, you could do it in a single jQuery line.
$('#errorr, #errorrarrow').hide();
这篇关于使用指定的ID隐藏元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文