Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show all nested DIVs inside a main DIV with title tag?

Tags:

html

jquery

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="apple">
  <div>Hi..</div>
</div>

And the jQuery

$('input#showapple').click(function(){
  $("div *[title='apple']").show(2000);
});

$('input#hideapple').click(function(){
  $("div *[title='apple']").hide(2000);
});
like image 238
Shrinivas Naik Avatar asked Oct 05 '22 23:10

Shrinivas Naik


1 Answers

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):

$('#showapple, #hideapple').click(function(){
    $("div[title='apple'] > div").toggle(2000);
});
like image 197
mattytommo Avatar answered Oct 10 '22 04:10

mattytommo