Click on an element that starts clicking on another element [jQuery]

I have a top menu with home , prodotti , info and contatti . Below is the accordion menu, in which the slide is always open, and when you click on the title, which changes it, and opens the relative slide.

screenshot

I would like that when I click, for example, on contatti in the top menu, it causes a click on contattaci in the accordion menu, so that the relative slide opens as if I clicked directly on contattaci (using jQuery).

screenshot2

The HTML of the top menu is as follows:

 <div id='cssmenu'> <ul> <li id="home" class='active'><span>Home</span></li> <li id="prodotti"><span>Prodotti</span></li> <li id="info"><span>Info</span></li> <li id="contact" class='last'><span>Contatti</span></li> </ul> </div> 

The accordion HTML menu is as follows:

 <div class="container"> <div id="demo"> <ol> ................... <li id="contattaci"> <h2><span>Contattaci</span></h2> <div> <iframe src="form.php"width="625px" height="400px" ></iframe> </div> <p class="ap-caption">e-mail</p> </li> ...... </ol> </div> <div> 

Therefore, when I click on the contatti element in the top menu (with id = " contact "), I would like to simulate a click on the " contattaci " in the accordion menu (with id = " contattaci "), so that the contact form slide opens next to " contattaci ".

I'm not sure if this is possible, anyway I tried using this jQuery code:

 <script> $(document).on('click', '#contact', function() { $("#contattaci").click(); }); </script> 

This does not work. Hope you can help me solve the problem.

EDIT . The css accordion menu uses css3, as well as the jquery.accordionpro.min.js jquery library, which uses the jQuery Swipe library ( https://github.com/jgarber623/jquery-swipe ). You can probably open the slide using the function in the jQuery Swipe library. What do you think? If you can help, let me know.

Link to the site for further analysis: http://tinyurl.com/m2u5t7d

+8
jquery click onclick
source share
2 answers

I would try this as follows:

 $(document).on('click', '#contact', function(event) { event.preventDefault(); $("#contattaci h2").click(); }); 
+11
source share
 $(document).on('click', '#contact', function(e) { $("#contattaci").trigger('click'); }); 
+1
source share

All Articles