jQuery Method of Viewing HTML Code for Selected Object

  • 2021-06-28 11:12:07
  • OfStack

This article provides an example of how jQuery looks at the HTML code for the selected object.Share it for your reference, as follows:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src='jquery-1.6.2.min.js'></script>
<title>jQuery View Selected Objects HTML Code </title>
</head>
<body>
<div>
 <div id="hb">dsaf</div>
</div>
<script>
 $(function(){
 alert($("#hb").get(0).outerHTML);
 });
</script>
</body>
</html>

The results are:

< div id="hb" > dsaf < /div >

(Note the difference with innerHTML here!)

More readers interested in jQuery-related content can view this site's topics: jQuery Common Plug-ins and Usage Summary, Ajax Usage Summary in jquery, jQuery Table (table) Operation Skills Summary, jQuery Drag and Skills Summary, jQuery Extension Skills Summary, jQuery Common Classic Skills Summary, andjQuery Animation and Utility Summary and jquery Selector Usage Summary

I hope that the description in this paper will be helpful to everyone's jQuery program design.


Related articles: