PDA

View Full Version : Testing to see if user is clicking on anchor


Fon
02-05-2008, 08:50 AM
So I have this click event happening in a linked js file:
if (!this.options.modal) ) {
Event.observe(this.popup, 'click', this.bring_to_front.bindAsEventListener(this));
Where "this" is the div popup object that uses this statement. Anyway, I want to add an extra condition. I only want it to go through, if the user is not clicking on an anchor. Is it
if ((!this.options.modal) && (!this.anchor))
I basically want a function that returns true / false if the object in an anchor. How do I do that in js?

Thanks.

A1ien51
02-05-2008, 03:32 PM
Play with this:

<script type="text/javascript">
function clickTest(event) {
event = event || window.event;
var elem = event.target || event.srcElement;
var tag = elem.tagName;
document.getElementById("output").innerHTML = "You clicked on a " + tag;

}

window.onclick = clickTest;
</script>

<div id="output">Click on something</div>

<span>a span</span><br/>
<a href="#" onclick="return false">A link</a><br/>
<div>a div</div>


Eric

rnd me
02-05-2008, 07:04 PM
So I have this click event happening in a linked js file:
I basically want a function that returns true / false if the object in an anchor. How do I do that in js?
Thanks.


unless you have some custom tags attributes in use, ( !! theTag.href) should return true for any anchor that does anything.