You can use this syntax: if ( $('#elementToBeUpdated').is('input,textarea') ) { // use val(); } else { // use text(); }
or you can take advantage of the empty return object (only one will execute): $('#element').filter('input,textarea').val(new); $('#element').not('input,textarea').text(new); or better yet, elements usually don't have a value attribute: (this.value) ? $(this).val(new) : $(this).text(new); - ricardo On Oct 19, 11:30 am, RotinPain <[EMAIL PROTECTED]> wrote: > @ Balazs Endresz: > You're right, and Ricardobeat has given the good answer ;) > Even if i'm working with Firebug I didn't notice this behavior between > value and text. > > @Remy: > yeah! I couldn't manage to put xml in jsbin. I followed the ajax video > without no success. > Any view where i pasted the xml (JS or HTML views) it was outputted > without tags. The only manner i found was to paste html encoded > caracters in the html view. So that the output was fine (at screen) > ( I do paste that in html view: <xml> <set > id="textfield">value for test 1</set> </ > xml> ) > Is there a simple way to use xml at jsbin ? like you do with json in > the ajax video ? Thanx for the jsbin app, it kills all !!!!! > > @ Ricardo: > val() is working fine in this case, thanx. Nice analysis of the FF > behavior with textarea text/value attributes ;) > > what i didn't mention is that the element to be updated could be any > element in the page (textarea, div or p ... ) > > The first code I wrote in dev was including a test case for the > element tagname before to update it, and i was right then! (But when i > saw that text() was working with textarea too (mainly in IE), i > deleted this test case using text() for updating any element content). > > Here's the test case I was using : > var viewer = $("[id='" + update[0] + "']"); > var viewertag = viewer.attr("tagName").toLowerCase() > if (viewertag == "textarea" || viewertag == "input") { > viewer.val( update[1] );//input detected} > > else { > viewer.text( update[1] );//other than inputs > > } > > Would there be a method to update any element without any test case ? > > Thank you all for you help. I now understand better why it does not > always work in FF (IE and SAFARI 3(win32) where working fine with the > code) !