Jump to content

Recommended Posts

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?

 

 

Link to comment
https://forums.phpfreaks.com/topic/203659-jquery-click-function-question/
Share on other sites

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";
   }
}
}

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.