.Trim $ () function is used to remove a blank character string ends. In the middle of the time will not be removed.
var STR = 'ends removal spaces left string, line, tab. ' ; RES = $ .trim (STR); the console.log (STR); the console.log (RES);
html (); // Sets or gets the element html content
text (); // text content
val (); // value value form
attr (); // attribute value (default and custom html provided value)
<div class="wrap">this is a wrapppppp <p>para</p> <mark>mark text</mark> <h2>header 2</h2> </div> var wrap = $('.wrap'); var res = wrap.html(); console.log(res); res = wrap.text(); console.log(res);
wrap.text('hhhhhhhhhh');
It will overwrite the contents of the page.
<input class="inp" type="text" value="the value"> var inp = $('.inp'); var res = inp.val(); console.log(res);
shown as:
attr
var h2 = $('.wrap h2'); var res = h2.attr('class'); console.log(res); h2.attr('class','h2'); res = h2.attr('class'); console.log(res); h2.attr('newattr','hi'); res = h2.attr('newattr'); console.log(res);