"JavaScript and jquery get H2 content"

Source: Internet
Author: User
Tags dname

Date written: 2016-7-13 11:05:07

There's a difference between JavaScript and jquery getting DOM content, and then look at an example

chestnuts :

Jquery-get the content in H3 and then convert the DOM to jquery
<!DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/TR/xhtml1/DTD/ Xhtml1-transitional.dtd "><HTMLxmlns= "http://www.w3.org/1999/xhtml"><Head><title>1-4</title><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" /><!--Introducing JQuery -<Scriptsrc=".. /scripts/jquery-1.3.1.js "type= "Text/javascript"></Script><Scripttype= "Text/javascript">//wait for the DOM element to finish loading.$ (document). Ready (function(){
The first method of obtaining, by ID
var name = $ ("#tagh"). html (); jquery Object Alert ("jquery object:" +name);

var dname = document.getElementById ("Tagh"). InnerHTML;//dom Object
Alert ("Dom object:" +dname);

The second method of fetching is obtained by using the name var name = document.getElementsByTagName ("H2"); Dom Object
var jOb = $ (name); jquery Object
Alert ("Dom object:" +name[0]. InnerHTML);
Alert ("jquery object:" +job. HTML ());
Or (also in the second category)
var domobj = document.getElementsByTagName ("h2") [0]; Dom object var $jQueryObj = $ (domobj);  jquery Object Alert ("Dom object:" +domobj.innerhtml); Alert ("jquery object:" + $JQUERYOBJ. html ());
});</Script></Head><Body><H2 id= "Tagh">Give me a chestnut.</H2><Ptitle= "tourist attraction most want to go:" >What's the best place to go?</P><ul><Li>Malta Antarctica/li><Li>Antarctica</Li><Li>Tropical Forest</Li></ul></Body></HTML>

"JavaScript and jquery get H2 content"

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.