codingmasterRS Posted June 11, 2011 Share Posted June 11, 2011 Hi guys, I have this img class <img src="avatars/21.png" class="online" onMouseDown="if(event.button==2){alert('Initiate IM session');}" /> now what I need is to change toe onMouseDown event so that it has an additional IF, the additional IF needs to check if class="online" or their is no class. Cheers in advance, tried googling couldn't find what I was after. All help much appreciated, Quote Link to comment https://forums.phpfreaks.com/topic/239038-javascript-that-detects-class/ Share on other sites More sharing options...
codingmasterRS Posted June 11, 2011 Author Share Posted June 11, 2011 NB: it must do it from a function and can use jquery NEW: <img src="avatars/21.png" class="online" onMouseDown="IM()" /> Quote Link to comment https://forums.phpfreaks.com/topic/239038-javascript-that-detects-class/#findComment-1228233 Share on other sites More sharing options...
requinix Posted June 11, 2011 Share Posted June 11, 2011 Forget the inline onmousedown: $(function() { $("img.online").click(function() { alert("Works"); }); }); Quote Link to comment https://forums.phpfreaks.com/topic/239038-javascript-that-detects-class/#findComment-1228284 Share on other sites More sharing options...
codingmasterRS Posted June 11, 2011 Author Share Posted June 11, 2011 requinix, thanks. But how do I get this to work? What do I put in the img tag? Quote Link to comment https://forums.phpfreaks.com/topic/239038-javascript-that-detects-class/#findComment-1228296 Share on other sites More sharing options...
codingmasterRS Posted June 11, 2011 Author Share Posted June 11, 2011 NB: It needs to work for rightclick! Quote Link to comment https://forums.phpfreaks.com/topic/239038-javascript-that-detects-class/#findComment-1228297 Share on other sites More sharing options...
codingmasterRS Posted June 11, 2011 Author Share Posted June 11, 2011 $(document).ready( function() { $("img.online").rightClick(function() { alert("Works"); }); }); does not work Quote Link to comment https://forums.phpfreaks.com/topic/239038-javascript-that-detects-class/#findComment-1228299 Share on other sites More sharing options...
requinix Posted June 11, 2011 Share Posted June 11, 2011 There is no .rightClick. Are you guessing? If you need right-click too (why? that's not typical) then use .mousedown() and event.which for the button. .mousedown(function(e) { if (e.which == 1 || e.which == 3) { // ... } }); Quote Link to comment https://forums.phpfreaks.com/topic/239038-javascript-that-detects-class/#findComment-1228503 Share on other sites More sharing options...
fugix Posted June 11, 2011 Share Posted June 11, 2011 to detect which mouse button was clicked, thus giving you the abilty to act accordingly, take a look at the event.button attribute Quote Link to comment https://forums.phpfreaks.com/topic/239038-javascript-that-detects-class/#findComment-1228510 Share on other sites More sharing options...
codingmasterRS Posted June 12, 2011 Author Share Posted June 12, 2011 http://abeautifulsite.net/blog/2008/05/jquery-right-click-plugin/ Quote Link to comment https://forums.phpfreaks.com/topic/239038-javascript-that-detects-class/#findComment-1228576 Share on other sites More sharing options...
codingmasterRS Posted June 12, 2011 Author Share Posted June 12, 2011 none of this is making sense, could you clarify and make it very clear please Quote Link to comment https://forums.phpfreaks.com/topic/239038-javascript-that-detects-class/#findComment-1228594 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.