That’s because you aren’t passing a reference to this in the JavaScript function call. this in the JavaScript function doesn’t refer to the same object as in the onClick example. Try this instead:
<li onClick="foo(this)"></li>
function foo(item){ alert(item.tagName); }
More Related Contents:
- How do I use ‘this” keyword in an object literal? [closed]
- Javascript call() & apply() vs bind()?
- Javascript “this” pointer within nested function
- this inside function
- The invocation context (this) of the forEach function call
- What object javascript function is bound to (what is its “this”)?
- javascript – document.write error?
- The reason to use JS .call() method?
- Function not calling within an onclick event
- JavaScript button onclick not working
- How to turn a String into a JavaScript function call? [duplicate]
- Function declarations inside if/else statements?
- Calling a JavaScript function returned from an Ajax response
- What’s the difference between window.location= and window.location.replace()?
- ES6 destructuring function parameter – naming root object
- React onClick function fires on render
- What is “function*” in JavaScript?
- JavaScript function order: why does it matter?
- JavaScript curry: what are the practical applications?
- How can I disable HREF if onclick is executed?
- What’s the difference between self and window?
- Get the weekday from a Date object or date string using JavaScript
- Why is this function wrapped in parentheses, followed by parentheses? [duplicate]
- ‘this’ keyword, not clear
- jQuery – How can I temporarily disable the onclick event listener after the event has been fired?
- window.close() doesn’t work – Scripts may close only the windows that were opened by it
- Calling a Function defined inside another function in Javascript
- Javascript – Precedence in hoisting
- jQuery asynchronous function call, no AJAX request
- What is the difference between onClick=”javascript: function(‘value’)'” and onClick=”function(‘value’);”? [duplicate]