jquery隐藏除特定类之外的所有div [英] jquery hide all but one div with a specific class
本文介绍了jquery隐藏除特定类之外的所有div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嘿所有
我有一个asp.net转发器,它生成一个div,它有一个名为newsItem的类分配给他们
我想做的就是编写一个函数隐藏上述类的所有div除了一个基于我传递给函数的整数参数的div
示例:
让我说我有5个div与类newsItem
如果我将数字1传递给函数,我想显示第二个div并隐藏其他4个div
提前感谢所有:)
解决方案
JQuery将其作为可以使用索引访问的数组对象。试试下面的代码。它应该工作
toggleNews = function (newsIndex){
( div.newsItem)。hide();
< BLOCKQUOTE>(
hey all
I have an asp.net repeater that generates divs that have a class called "newsItem" assigned to them
what I wanna do is write a function that hides all the divs of the above mentioned class except one div based on an integer parameter that i pass to the function
Example:
Lets say i have 5 divs with the class "newsItem"
if I pass the number 1 to the function, I want to show the 2nd div and hide the other 4 divs
thanks all in advance :)
解决方案
JQuery takes it as an array object which can be accessed with a index. try the below code. it should work
toggleNews = function(newsIndex) {
("div.newsItem").hide();
(
这篇关于jquery隐藏除特定类之外的所有div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文