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 ?
$(function () { $('#submit').on('click', function () { var val = $.trim( $('textarea').val() ); var text = $('<div/>').html(val).find('u').text(); // console.log(text); }) });
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
Post a Comment