jquery - Return the content from textarea with element inside -


i make script extract me within defined element. in exemple it's <u> element.

html

<textarea cols="75" rows="25" id="textshit"><u>sd</u></textarea><br>     <input type="submit" name="submit" id="submit"/>     <div id="res"></div> 

js

$(function(){     $('#submit').on('click',function(){         $('textarea:contains("u")').each(function() {             //$('#res').html($(this).val()+'<br>');             alert($(this).val());         })     }); }); 

i when hit submit, in <div class="res"> returns what's inside every <u>.

how achieve ?

http://jsfiddle.net/warface/ewve8/

$(function () {     $('#submit').on('click', function () {         var val = $.trim( $('textarea').val() );         var text = $('<div/>').html(val).find('u').text();         // console.log(text);     }) }); 

http://jsfiddle.net/ewve8/1/

update: can use map method , join returned array's elements:

$('#submit').on('click', function () {     var val = $.trim( $('textarea').val() ),         text = $('<div/>').html(val).find('u').map(function(){             return $(this).text();         }).get();      $('.res').html( text.join('<br>') );  }) 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -