开发者

jQuery simple value get issue with .val()

开发者 https://www.devze.com 2023-03-09 02:06 出处:网络
I have the following code: $(\'.document\').ready(function(){ alert($(\'font.someClass\').val()); }); Here is a Fiddle with it.

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 开发者_Go百科set the value of a font tag.


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


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());
});


This will get you the text:

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

精彩评论

暂无评论...
验证码 换一张
取 消