Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery simple value get issue with .val()

Tags:

jquery

get

I have the following code:

$('.document').ready(function(){
   alert($('font.someClass').val());
});

Here is a Fiddle with it.

Does anyone know why I can not return the value of a font tag?

Am I to assume that you are not allowed to call the value or set the value of a font tag.

like image 214
John Avatar asked Dec 10 '25 09:12

John


2 Answers

.text() not .val() - .val() is for form elements.

like image 59
Rabbott Avatar answered Dec 13 '25 00:12

Rabbott


The val() method get values from value which exists for form elements (like input). You is looking to get the text from some DOM element, so use the text() method.

I updated your Fiddle here with the code:

$(document).ready(function() {
   alert($("font.someClass").text());
});
like image 43
Erick Petrucelli Avatar answered Dec 13 '25 01:12

Erick Petrucelli



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!