RIRedinPA Posted June 2, 2010 Share Posted June 2, 2010 I'm taking some time to learn stuff and am trying to figure out how jquery can recognize a click event without a handler... So in jquery you can do something like this $('.clickme').click(Function() { //do stuff }); <p class="clickme">By clicking on this you somehow trigger the jquery click function</p> So I figure they are tracking window events through the DOM (document.click). I've started with this bit of code, which I found through The Google. document.onclick = getEl(); function getEl() { alert(window.event); } but the alert fires off when the page loads with an undefined message. Any ideas how to accomplish this? Quote Link to comment https://forums.phpfreaks.com/topic/203659-jquery-click-function-question/ Share on other sites More sharing options...
prestonwinfrey Posted June 2, 2010 Share Posted June 2, 2010 <script> document.onclick = getEl; function getEl() { alert(window.event); } </script> Quote Link to comment https://forums.phpfreaks.com/topic/203659-jquery-click-function-question/#findComment-1066833 Share on other sites More sharing options...
RIRedinPA Posted June 3, 2010 Author Share Posted June 3, 2010 Preston...I did have it wrapped in script tags, my bad for not including it in the submitted code...anyways, here is what I finally did...kind of a blunt instrument and narrowly defined for my use but someone might get something out of it...would love to see any modifications to make it better... what I am doing is displaying a production schedule for an online store...this allows production designers and others associated with the store to see who is doing what and when, the schedule, as most things with too many cooks, is a page real estate pig, takes up a full screen, even after I chopped it up a lot with abbreviations for titles and what not. And of course those who have to use it on a daily basis whine about having to, gasp, scroll to see all the info or input their own... Such is the life of a programmer. Anyway, to make all parties happy I took non critical info and placed it in a hidden row beneath the item's critical info...to access it the user clicks on the item name (first field) and then the hidden data is revealed. Now to work on a nice slide for that data... function functionCheck(e) { //get which element was checked var targ; if (!e) { var e=window.event; } if (e.target) { targ=e.target; } else if (e.srcElement) { targ=e.srcElement; } // defeat Safari bug if (targ.nodeType===3) { targ = targ.parentNode; } if (targ.tagName === "P") { //get parent element var myParentClasses = targ.parentNode.className; //loop through all the parent classes var myParentClassesArray = myParentClasses.split(" "); for(var c=0; c<myParentClassesArray.length; c++) { if (myParentClassesArray[c].indexOf('tablerow') != -1) { myParentClass = myParentClassesArray[c]; } } var classNameArray = myParentClass.split("_"); var thisid = classNameArray[1]; var obj = 'fileinfo_' + thisid; //toggle if (document.getElementById(obj).style.display === "none") { document.getElementById(obj).style.display = "block"; } else { document.getElementById(obj).style.display = "none"; } } } Quote Link to comment https://forums.phpfreaks.com/topic/203659-jquery-click-function-question/#findComment-1067164 Share on other sites More sharing options...
trq Posted June 3, 2010 Share Posted June 3, 2010 Preston...I did have it wrapped in script tags, my bad for not including it in the submitted code... I think he was more pointing out the fact that you had.... document.onclick = getEl(); and not.... document.onclick = getEl; Hence the function getEI was being envoked when the page loaded. Quote Link to comment https://forums.phpfreaks.com/topic/203659-jquery-click-function-question/#findComment-1067168 Share on other sites More sharing options...
prestonwinfrey Posted June 3, 2010 Share Posted June 3, 2010 You are exactly right, Thorpe. Quote Link to comment https://forums.phpfreaks.com/topic/203659-jquery-click-function-question/#findComment-1067184 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.