0

With this code:

$(document).on('click', '.docs-tag', function(event){
    console.log($(event.target))
})

I expect to see:

[<some html>]

but instead get:

[span.icon-tag docs-tag child_hover dropdown-open, context: span.icon-tag docs-tag child_hover dropdown-open, constructor: function, init: function, selector: "", jquery: "1.8.2"…]

I have recently upgraded to jQuery 1.8.2. Has there been a change in how $(event.target) is handled?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Rich Tier
  • 9,021
  • 10
  • 48
  • 71
  • 1
    It's just how the DOM element (or jQuery object) is displayed in the console. No need to worry about it. – Felix Kling Jun 03 '13 at 22:16
  • if the element has an attribute 'data-thing'='some value', then doing $(event.target).data('thing') returns undefined. – Rich Tier Jun 03 '13 at 22:17
  • Works fine for me: http://jsfiddle.net/FxQJk/. But I use 1.8.3 in the fiddle, if it makes a difference. – Felix Kling Jun 03 '13 at 22:20
  • possible duplicate of [console.log() not outputting HTML of jQuery selection object](http://stackoverflow.com/questions/13268015/console-log-not-outputting-html-of-jquery-selection-object) – Felix Kling Jun 03 '13 at 22:21

3 Answers3

3

This has to do with changes in the browser output, it doesn't have to do with jQuery. Here's a thread on the subject - console.logging.

Community
  • 1
  • 1
rogMaHall
  • 681
  • 4
  • 9
1

If you want to see the DOM node, do this:

console.log($(event.target)[0]);
Adam Jenkins
  • 51,445
  • 11
  • 72
  • 100
0

event.target returns the DOM element, so you can retrieve any property/ attribute that has a value

try this

$(event.target).text()
PSR
  • 39,804
  • 41
  • 111
  • 151