I'm trying to get the value from the HTML tag. Not the text itself, but the attribute value. What am I doing wrong?
$('label').click(function() {
$('p').text(($(this).val()));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<label value="hello">click</label>
<p></p>
valueisn't valid attributes forlabel. Valid attributes arefor, the common Global attributes and custom data attribute (data-*)data-*it allows you to use any arbitrary string. ex.data-value="hello"data-*? Put it where value is? How would I get the value back in JQuery?[...]Description: Return the value at the named data store for the first element in the jQuery collection, as set by data(name, value) or by an HTML5 data-* attribute.[...]