jquery - Setting Value or Text to an Unknown Element -


i'm trying set value of element, if value can't set (because it's not input element such input, select or textarea) must element can populated text()

var someval = "my value"; //try , set value $("#some_el").val(someval); // if couldn't set $("#some_el").text(someval); 

something that. there method allow me in jquery?

thanks

you can chain methods, jquery checks internally, 1 of methods work:

$("#some_el").val(someval).text(someval); 

http://jsfiddle.net/3btty/

another option checking whether selected dom element has specific property value or textcontent or not, allows use text or val method getter:

var $elem = $('#some_el'),     method = 'value' in $elem[0] ? 'val' : 'text';  var value = $elem[method](); 

note method works 1 selected element, more 1 selected element can use .each() method.

http://jsfiddle.net/htuns/


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -