jQuery(“.myContent”).hide()语句的javascript等价物是什么?

jQuery(“.myContent”).hide()语句的javascript等价物是什么?,javascript,jquery,Javascript,Jquery,我需要jQuery hide()的javascript等价物。下面语句的javascript等价物是什么 jQuery(".myContent").hide() 在所有现代浏览器以及IE8上,您都可以使用它,您经常会发现它与Array.prototype.forEach或Array.prototype.slice结合使用: Array.prototype.forEach.call(document.querySelectorAll(".myContent"), function(el) {

我需要jQuery hide()的javascript等价物。下面语句的javascript等价物是什么

jQuery(".myContent").hide()

在所有现代浏览器以及IE8上,您都可以使用它,您经常会发现它与
Array.prototype.forEach
Array.prototype.slice
结合使用:

Array.prototype.forEach.call(document.querySelectorAll(".myContent"), function(el) {
    el.style.display = "none";
});
它几乎得到了普遍支持,比IE8不支持的
getElementsByClassName
稍微多一点。(Array.prototype.forEach.call的
部分为我们提供了一种方便的方法来循环结果。)

在适当的现代浏览器(或带有垫片)上,您可以将其与:

或者技术上你可以这样做:

from(document.queryselectoral(“.myContent”),函数(el){ el.style.display=“无”; });

…因为
Array.from
接受映射函数

在这两种情况下,为了简洁起见,您可能希望为自己提供一个包装器函数


如果您只需要隐藏该类的第一个元素,那么它就是
querySelector

// Assumes there *will* be a match, throws error if not
document.querySelector(".myContent").style.display = "none";

var x=document.getElementsByClassName('myContent');
对于(var i=0;i
// Assumes there *will* be a match, throws error if not
document.querySelector(".myContent").style.display = "none";
// Doesn't make that assumption
var el = document.querySelector(".myContent");
if (el) {
    el.style.display = "none";
}
var x = document.getElementsByClassName('myContent');
for (var i=0;i<x.length;i++){
  x[i].style.display = 'none';
}