Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
354 views
in Technique[技术] by (71.8m points)

onclick - Click on an element triggers the click on another element [JQuery]

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

screenshot

I would like that when I press for example on contatti in the top menu it triggers the 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 looks like this:

<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 HTML of the accordion menu looks like this:

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

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

I'm not sure that it is possible, anyway I tried using this JQuery code:

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

This doesn't work. I hope you can help me to fix the problem.

EDIT: The css accordion menu uses css3 but also a jquery library called jquery.accordionpro.min.js that makes use of JQuery Swipe library (https://github.com/jgarber623/jquery-swipe). Probably the slide can be opened using a function in Jquery Swipe library. What do you think? If you can help let me know.

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I would try it this way:

$(document).on('click', '#contact', function(event) { 
    event.preventDefault(); 
    $("#contattaci h2").click(); 
});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...