I have my main div
with title="apple"
and nested divs with no title tag. When I write code to show main div with "apple"
title only the main div
is getting displayed, the nested divs doesn't get displayed. How to display all child divs even if they don't have title tag? Here is the code below.
我有我的主div与title =“苹果”和嵌套的div没有标题标签。当我编写代码以显示带有“apple”标题的主div时,只显示主div,嵌套的div不会显示。即使没有标题标签,如何显示所有子div?这是下面的代码。
<div title="apple">
<div>Hi..</div>
</div>
And the jQuery
和jQuery
$('input#showapple').click(function(){
$("div *[title='apple']").show(2000);
});
$('input#hideapple').click(function(){
$("div *[title='apple']").hide(2000);
});
4 个解决方案
#1
4
You can do them both in one using toggle
plus you don't need to specify the input
argument when selecting by ID, jQuery will only return the first matched element on ID (because there should only be one):
您可以使用切换在一个中执行它们,并且在按ID选择时不需要指定输入参数,jQuery将仅返回ID上的第一个匹配元素(因为应该只有一个):
$('#showapple, #hideapple').click(function(){
$("div[title='apple'] > div").toggle(2000);
});
#2
0
<div id="apple">
You select elements using attribute ID, not title.
您使用属性ID选择元素,而不是标题。
#3
0
your selector seems to be a little bit off
你的选择器似乎有点偏
$('input#showapple').click(function(){
$("div[title=apple]").show(2000);
});
also, you should really be using classes for this and not the title.
另外,你应该真正使用类而不是标题。
#4
0
Try:
尝试:
$('input#showapple').click(function(){
$("div[title='apple'] > div").show(2000);
});
You will select all the div with title apple and any child div's within it.
您将选择标题为apple的所有div以及其中的任何子div。
http://jsfiddle.net/rpZbL/
#1
4
You can do them both in one using toggle
plus you don't need to specify the input
argument when selecting by ID, jQuery will only return the first matched element on ID (because there should only be one):
您可以使用切换在一个中执行它们,并且在按ID选择时不需要指定输入参数,jQuery将仅返回ID上的第一个匹配元素(因为应该只有一个):
$('#showapple, #hideapple').click(function(){
$("div[title='apple'] > div").toggle(2000);
});
#2
0
<div id="apple">
You select elements using attribute ID, not title.
您使用属性ID选择元素,而不是标题。
#3
0
your selector seems to be a little bit off
你的选择器似乎有点偏
$('input#showapple').click(function(){
$("div[title=apple]").show(2000);
});
also, you should really be using classes for this and not the title.
另外,你应该真正使用类而不是标题。
#4
0
Try:
尝试:
$('input#showapple').click(function(){
$("div[title='apple'] > div").show(2000);
});
You will select all the div with title apple and any child div's within it.
您将选择标题为apple的所有div以及其中的任何子div。
http://jsfiddle.net/rpZbL/