0

In my code I did something like

$("#jdoe").append("<h3>Test</h3>");

html

<html>
<head>
</head>
<body>
<div id="jdoe"></div>
</body>
</html>

It worked as expected (The text Test displays in a h3), I was expecting that if I do a view source in my browser I would see something like

<html>
<head>
</head>
<body>
<div id="jdoe"><h3>Test</h3></div>
</body>
</html>

Please correct me if my expectations are wrong

tawheed
  • 5,565
  • 9
  • 36
  • 63

4 Answers4

2

You haven't changed the source of your page, you've changed your DOM. If you use the developer tools for your preferred browser, you'll see the changes there.

I think you can get developer tools for all browsers by hitting F12.

Daniel Gimenez
  • 18,530
  • 3
  • 50
  • 70
1

Your expectations seem correct...

http://jsfiddle.net/4Uq33/

But to see what it looks like you'll have to use something like Chrome's Inspect Element, not view source.

But I'd suggest doing it more like this:

$("#jdoe").append($("<h3>").text("Text"));
Samuel Reid
  • 1,756
  • 12
  • 22
  • Just curious but what is the benefit of doing it this way over the OP's? – War10ck Jul 31 '13 at 18:48
  • You can end up chaining more jQuery functions onto the end of it if you need to. For example, `$("#jdoe").append($("

    ").text("Test").css("color","#f00").on("click",doSomething));`

    – Samuel Reid Jul 31 '13 at 18:55
  • Nice. Learn something new everyday. Thanks buddy! :) – War10ck Jul 31 '13 at 18:56
  • 1
    @War10ck - The real benefit is that it uses document.createElement internally, so it actually creates the elements instead of just appending a string of HTML. Creating actual DOM elements is IMO a better approach, but the proper syntax would be `$('

    ', {text:'Text'});`
    – adeneo Jul 31 '13 at 19:31
  • @adeneo I like that approach the best. Thanks for explanation buddy. :) – War10ck Jul 31 '13 at 19:39
0

your "view source" will be as the same html you get from the server.

Any manipulation with javascript/jquery will not apply.

0

You need to access the console, not the source. In Google Chrome this can be done by pressing Ctrl+Shift+J, from there you can access the other developer tools.

notquiteamonad
  • 1,159
  • 2
  • 12
  • 28