I expect this to print "a" because when I call foo(this)
, the argument seems to be the link tag.<a href="javascript:foo(this)"> passes Window, I want the tag element itself
<script type="text/javascript">
function foo (e) {
alert (e .tagName);
}
</script>
<a href="javascript:foo(this)">click</a>
Instead, it prints "undefined". If I alert(e)
it says "object Window". How do I make foo
know which element launched it? Without passing/looking up ids.
यदि आप 'console.log (e.tagName) का उपयोग करते हैं, तो' – mgraph
मुझे लगता है कि आपको एक 'href' की आवश्यकता है जो जावास्क्रिप्ट फ़ंक्शन कॉल नहीं है। यदि आप 'href =" # "' का उपयोग करते हैं तो यह काम करना चाहिए और आप स्क्रिप्ट निष्पादन के लिए 'onclick = "function ...' का उपयोग करते हैं। मुझे लगता है कि यह एक ऐसा है कि एंकर टैग उचित के बिना असली टैग नहीं है 'href'। – andyb
obj के लिए' e' का उपयोग न करें। 'e' ईवेंट ऑब्जेक्ट – gdoron