0
How to go through the whole DOM and find a certain element in jQuery?
Yes, by clicking on li
of classe="home"
, open the div
of classe="submenu"
.
<body class="home">
<!-- Header -->
<div class="wrap-header">
<div class="row">
<div class="area-logo-responsive hide-for-large-up small-12 medium-12 columns">
<a href="index.php/home"><h1><img src="img/theme/logo-responsive.png" title="Openweb " alt="Openweb " /></h1></a>
</div>
</div>
<!-- Row do Menu e do Logo -->
<div class="row">
<div class="large-3 columns show-for-large-up">
<div class="area-logo">
<a href="index.php/home"><h1><img src="img/theme/logo-openweb.png" title="Openweb " alt="Openweb " /></h1></a>
</div>
</div>
<div class="small-12 medium-12 large-9 columns">
<div class="area-menu hide-for-medium-only hide-for-small-only">
<ul class="menu">
<li menu="home" class="home"><a href="#">Home</a></li>
<li><a href="#">Produtos e Serviços</a></li>
<li><a href="#">Central do Cliente</a></li>
<li><a href="#">Sobre a Openweb</a></li>
<li class="last"><a href="#">Contato</a></li>
<li class="login"><span class="lock"></span><a href="#">Login</a>
<div class="wrap-login show-for-large-up">
<div class="area-login">
<?php include('include-area-login.php'); ?>
</div>
</div>
</li>
</ul>
</div>
<div class="area-menu-response hide-for-large-up">
<button class="btn-home">Produtos e Serviços</button>
<button class="btn-more">Menu <span>▽</span></button>
<div class="clear"></div>
<div class="menu-hided-left">
<ul>
<li><a href="#">Hospedagem de Sites</a></li>
<li><a href="#">Servidores Linux</a></li>
<li><a href="#">Facilitta Mail Marketing</a></li>
<li><a href="#">Google Adwords</a></li>
<li><a href="#">Instalação de Blog</a></li>
</ul>
</div>
<div class="menu-hided">
<ul>
<li><a href="#">Home</a></li>
<li class="btn-submenu" ><a href="javascript:void(0);">Central do Cliente +</a>
<ul class="mais-submenu">
<li><a href="#">item 1</a></li>
<li><a href="#">item 2</a></li>
<li><a href="#">item 3</a></li>
<li><a href="#">item 4</a></li>
</ul>
</li>
<li class="btn-submenu"><a href="javascript:void(0);">Sobre a Openweb +</a>
<ul class="mais-submenu">
<li><a href="#">item 1</a></li>
<li><a href="#">item 2</a></li>
<li><a href="#">item 3</a></li>
<li><a href="#">item 4</a></li>
</ul>
</li>
<li><a href="#">Contato</a></li>
<li><a href="#">Login</a></li>
</ul>
</div>
</div>
</div>
</div><!-- Fecha Row da Header -->
</div><!-- Fecha Wrap-Header -->
<!-- Wrap-Drop Menu Header -->
<div class="wrap-menu">
<div class="row">
<div class="submenu show-for-large-up large-12 columns">
<ul>
<li><a href="#">Hospedagem de Sites</a></li>
<li><a href="#">Servidores Linux</a></li>
<li><a href="#">Facilitta Mail Marketing</a></li>
<li><a href="#">Google Adwords</a></li>
<li><a href="#">Instalação de Blog</a></li>
</ul>
</div>
</div><!-- Fecha Row do Menu-->
</div><!-- Fecha Wrap Menu -->
Can you give more details? If you’re using jQuery, you don’t have to go through the whole DOM to find an element. What are you really trying to do?
– bfavaretto
I have a read with a menu. When I click on this read I wanted to open a div that was somewhere else in the code.
– dsantoro
Can’t use it like this
$("#id_do_menu").onclick(function () { //open div });
?– Felipe Avelar
Okay, but does this div have an ID, a class, anything that allows you to identify it in the document? Because in jQuery you use
$('seletor-para-achar-sua-div')
and ready (any DOM crossing that is necessary jQuery does for you).– bfavaretto
I can’t, jquery doesn’t work like this, the only thing I know is to use Parent() and such. But it would be very handy.
– dsantoro
Look, if you want to cross the DOM, don’t use jQuery, use
firstChild
andnextSibling
that’s enough. But I’m sure there is a very simple way to get what you want using jQuery, just explain in detail (please [Edit]and the question with these details, your HTML, which div wants, etc). Otherwise your question can be closed because it is very vague.– bfavaretto
I’d paste the code but I don’t know how to make it cute.
– dsantoro
Use the button
{}
editor. And don’t use tabs, only spaces.– bfavaretto
I pasted the code. I know you can use Parent(), next() and such but it would be an ugly and extensive code.
– dsantoro
For me the question is still confused... but why not
$('.home').click(function(){ $('.submenu').show(); })
?– bfavaretto
Home is many levels "inside" the wrap-menu. I would have to return to the "wrap-menu", give find and find the element q I want.
– dsantoro
Igorem. It worked out this simple way lol.
– dsantoro