Jquery returning Object DomWindow
I am trying to get the value of a link, but instead of the link as my object I am getting [Object DOMWindow] in the alert.
Here is my code:
<script type="text/javascript">
function showToggle(link) {
var x = this
alert(x);
}
</script>
<a class=开发者_JS百科"toggleLink" href="#" onclick="showToggle(this);">Sharing</a>
I am adding this code to a page. There is much more code that is not included. I only showed when I added.
The way you're calling it, this
is the same as window
, hence the result. You want
var x = link;
By link, do you mean the url? Also, you're using this
as the variable, not link
, which returns the window
, not the link.
This will work:
function showToggle(link) {
var x = link.href;
alert(x);
}
精彩评论