jQuery is not picking up correct values from a Div Tag
I want to pick up the values in a Div tag like which is some what like this
<html>
<head> </head>
<body>
<div id="page">
<html>
开发者_运维问答 <head></head>
<body> Hellow World </body>
</html>
</div>
</body>
</html>
I want to select the content inside a div tag .
var msg = $("#page").html();
alert(msg);
this code is not working . i want that whole 2nd page along with the HTML tag is copied. How do i do that ?
I want the output to be the WHOLE thing INCLUDING the HTML tags
Use text() instead of html().
var msg = $("#page").text();
alert(msg);
// Hellow World
You can't use the <html>
and <body>
tags like that - there can only be one of each, in very clearly defined positions. Did you want to use an iframe?
When the browser parses that page it'll ignore the inner <html>
and <body>
tags.
If you want to have a page within a page, you'll need to use an <iframe>
.
Or if you want to avoid an <iframe>
(which has it's own issues) and still use proper html, put the content as the value of a hidden <textarea>
. Then you can use .val()
.
You can not use html tag inside html
Preferably use Iframe inside html to write html inside html
You can use Iframes like this
<html>
<head>
</head>
<body>
<font face="verdana,arial" size="3">
<div align="center">
<p>
<a href="http://www.altavista.com" target="iframe1">AltaVista.com</a> |
<a href="http://www.aol.com" target="iframe1">AOL.com</a> |
<a href="http://www.lycos.com" target="iframe1">Lycos.com</a> |
<a href="http://www.yahoo.com" target="iframe1">Yahoo.com</a>
<p>
<iframe name="iframe1" width="600" height="400" src="http://www.stackoverflow.com" frameborder="yes" scrolling="yes">
</iframe>
<p>
</font>
</div>
<!--name="iframe1"
- Set all links to target the iframe1 name when you want the contents of the iframe to change from links on the originating page.
width="600" - Width of the iframe
height="400" - Height of the iframe * Width and height can be expressed in pixels or percent
src="http://www.yahoo.com" - Initial page that will fill in the iframe
frameborder="yes" - Border around the iframe is displayed by default
scrolling="yes" - Allow scrollbars around the iframe for navigation Vaild values are yes, no and auto
align="" - Valid entries are left and right left is set by default
-->
</body>
</html>
精彩评论