Difference between .html() and .text() functions in jQuery
by
Dwarika Dhish Mishra
·
March 24, 2013
Difference between .html() and .text() functions in jquery:
.html() can be used to get the contents of inside an element. If your selector expression matches more than one element, only the first match will have its HTML content returned:
here is an example:
- list sample 1
- list sample 2
- list sample 3
now if you are using .html():
$(‘.html-function-demo’).html();
your output is:
- list sample 1
- list sample 2
- list sample 3
now if you are using .text():
$(‘.html-function-demo’).text();
your output is:
list sample 1 list sample 2 list sample 3
due to different properties of HTML Parsers of your browser, the output for your function varies in the manner that the output will be in one line or continuous one or with spaces and linebreaks.
Both functions return strings as their output.
Related
Tags: difference between .html and .textdifference between .html() and .text() functions in jqueryHTML and Jquery +JavaScriptjQuery
Dwarika Dhish Mishra
My name is Dwarika Dhish Mishra, its just my name and I am trying to bring the worth of my name in to actions and wants to be the solution not the problem. I believe in spreading knowledge and happiness. More over I am fun loving person and like travelling a lot.By nature I am a tester and a solution maker. I believe in the tag line of http://ted.org “Idea worth spreading” . For the same, I have created this blog to bring more and more learning to tester fraternity through day to day learning in professional and personal life. All contents are the part of my learning and so are available for all..So please spread the contents as much as you can at your end so that it could reach to every needful people in testing fraternity.I am pretty happy that more and more people are showing interest to become the part your Abode QA blog and I think this is good sign for us all because more and more content would be before you to read and to cherish.You may write or call me at myEmail id: dwarika1987@gmail.com
Cell: 9999978609
You may also like...
This is a fantastic blog from which people can learn a lot. It is very informative and is explained in…
Thanks for sharing such knowledgeable Content on Automation testing, to know how to enhance the performance of ERP's like Oracle…
Thanks.. this list is much needed.
This one is also good to use. Thanks for sharing this.. Might be we can also add it in list…
How about youtube-dl?