0

I have a click function that passes the following dom as this:

<span class="tcloud label label-large label-primary" data-c="1" data-n="environment"> environment </span> 

How can I use jquery to select for the values of the html5 data attributes?

$(document).ready(function() { $('span.tcloud').click( function () { console.log(this) // returns the above dom console.log($(this)) // returns an error console.log(this.data("data-c")) // returns Uncaught TypeError: Object #<HTMLSpanElement> has no method 'data' 

2 Answers 2

1

Personally, I simply use

var values = $("element").attr("data-c"); 
Sign up to request clarification or add additional context in comments.

1 Comment

Uncaught TypeError: Object #<HTMLSpanElement> has no method 'attr' console.log(this.attr("data-c"))
0

you can get the value by using its id in following way.

 $('span.tcloud').click( function () { console.log( $('#element').val()); } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.