Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
5
rated 0 times [  12] [ 7]  / answers: 1 / hits: 41913  / 14 Years ago, mon, may 24, 2010, 12:00:00

i use such code to access item



function f(id){

$(#+id).val(); // with analogy $(#id item)
}


is it correct? is any other methods?


More From » jquery

 Answers
7

If you want to return the value of an element with specified id, then yes as that is what seems to be logical purpose of your function:



function f(id){
return $(# + id).val();
}


The functions should assume that an element with specified id exists and then it returns you the value of that element. This should work for input fields as well as textarea. If however, it is any other element, you might want to use html() or text() instead of val() eg:



function f(id){
return $(# + id).html();
// return $(# + id).text();
}

[#96701] Thursday, May 20, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
margaritakristinak

Total Points: 502
Total Questions: 127
Total Answers: 98

Location: England
Member since Mon, May 17, 2021
3 Years ago
;