简体   繁体   中英

Attaching multiple click events with same div in Jquery

I have one div and there are two events associated with it first is a click and another a popover trigger which also gets triggered on click .

Now with first click i need to modify the href attribute of the div and second popover event should pick this modified href and opens up a popover with content fetched from href.

The problem i am facing (looks liek to me ) is second popover triggers still picks up old value and appears to me that the sequence/order in which i registered the events is not maintained . How can I solve this problem.

Here is the my code sample:

retVal = originalURL;

retVal = jQuery('#'+'linkhere').click(getHashPageClick); // thsi function returns a href
(the value is correctly returned )

jQuery('#'+'linkhere').popoverTrigger(retVal); // thsi function opens up a popover with contents fetched from href URL.

but its still picking original URL. Can someone help.

call the popovertrigger after you call the gethashpage. That should do the trick.

jQuery('#'+'linkhere').click( function() {
  getHashPageClick();
  popOvertrigger();
})

Remember you can specifcy a function to your click function, so you can do a chain of events there

The problem is the order the events are firing. There may be a tricky solution using event propagation and bubbling and other fancy things, but there's a simpler solution. Just use mousedown !

$('#'+'linkhere').mousedown(getHashPageClick);

萤火虫示例

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM