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"