1

I want to trigger click on an icon(image) with specific class/id using onclick (or using any other way) of another button. Please see image for reference. Clicking "1" should trigger "2". Currently I am calling a javascript function "launchTopWM" which use following code to trigger click:

$(".custom_toggle_menu_default").trigger("click"); 

But i am wondering if i can call this code or perform this fucntionality using its click etc, something like href='javascript:$(".custom_toggle_menu_default").trigger("click");'

Following is the Code:

HTML 1:

 <img class="custom_toggle_menu_default" src="cc/tt/uu/images/launchTopWM.png">

HTML 2:

<a id="tsp" class="sp" href="launchTopWM()">CNw</a>
0

2 Answers 2

1

Give an id to the element and show the second anchor through pure javascript.

<!DOCTPE html>
<html>
<head>
     <title> Button style </title>
     <style>

     </style>
</head>
<body>


<a href="javascript:void(0)" onclick="getElementById('button').click()" > click me </a>
<button id="button">  Buton </button>


    

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <script>
       $('#button').click(function(){
           alert('Buttons has been clicked');
       });
    </script>
</body>
</html>

Sign up to request clarification or add additional context in comments.

1 Comment

Very nice example but you are setting "display" attribute and i need to trigger "click" of another icon.
1

Trigger example, Hope it will give you the idea

<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Triggger</title>
  <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<button id="tiggerCall">Trigger Focus</button>
<input type="text" placeholder="Onclick Call Focus" value=''>
<script>
$( "#tiggerCall" ).click(function() {
  $( "input" ).trigger( "focus" );
});
$( "input" ).focus(function() {
  $( "<span>Text box clicked</span>" ).appendTo( "body" ).fadeOut( 1000 );
});
</script>
</body>
</html>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.