Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to bind click event of div

Tags:

jquery

<div id="profile_ops" style="display:none">
  <button class="ybutton" id="viewclick" >View</button>&nbsp;
  <button class="ybutton" id="editclick" >Edit</button>&nbsp;
  <button class="ybutton" id="change_pswd" >Change Password</button>&nbsp;
  <button class="ybutton"  id="change_pic" >Change Picture</button>&nbsp;
</div>

in this i show this div on particular condition and i hide the view button but on edit click i show the view button but i want to give click event of view button where should i give the click event of div ?

i have tried giving the click event in edit click but it is giving me errro?

like image 812
XMen Avatar asked Oct 09 '10 06:10

XMen


People also ask

Can I apply click event on a div?

To add a click event listener on div tag using JavaScript, we can call the addEventListener method on the selected div. to add a div with a class. Then we write: const div = document.

Which method is used to set a click event on a button?

jQuery click() Method The click event occurs when an element is clicked. The click() method triggers the click event, or attaches a function to run when a click event occurs.

How do you fire a click event on an element?

The HTMLElement. click() method simulates a mouse click on an element. When click() is used with supported elements (such as an <input> ), it fires the element's click event. This event then bubbles up to elements higher in the document tree (or event chain) and fires their click events.

How do I trigger a click event without clicking?

If you want native JS to trigger click event without clicking then use the element id and click() method of JavaScript.


1 Answers

just assign the client event to each one

$(document).ready( function() {

  $("#viewclick").click( function() {
    // this will fire when you click view
  });
  $("#editclick").click( function() {
    // this will fire when you click edit
    // hide the view button here and upon submit, show it again
    // like $("#viewclick").hide() or $("#viewclick").fadeOut()
  });

});
like image 156
balexandre Avatar answered Oct 06 '22 12:10

balexandre