Get div value from jquery
4 answers
use jquery attr ()
Get the value of an attribute for the first element in a set of matched elements, or set one or more attributes for each matched element.
try it
alert($('#div1').attr('value'));
OR
$('#div1').on("click", function(a) {
alert($(this).attr('value')); //doesnt work
});
+5
source to share
If you can choose not to use native HTML attributes, you will run into validation problems, html5 data attributes are your best bet. This allows you to create your own attributes suitable for storing this type of data. For example:
<div data-num="12" id="div1">some content</div>
$('#div1').on('click', function(){
alert($(this).data('num'));
});
+1
source to share
alert($('#div1').attr('value'));
Must do the trick. All element attributes can be read and set via jQuery.attr ()
The jQuery.live method has been deprecated (v1.7) and removed (1.9), so use jQuery.on as shown in the demo.
0
source to share