jQuery: if i use .html to set the html content of an element, why it didn't displayed in source code
For example, I use:
$('test-div').html("<div></div>")
Actually the html is changed开发者_Go百科, but when I click "view source" from the browser, in browser the html is not changed, is it a bug for the browser?
Thanks.
No... when you view source you are looking at what was actually sent as the HTTP Response from the server. When using JQuery you are manipulating the DOM, which is an in-memory representation of the rendered page.
This is because this changes the HTML (actually the DOM) that is seen by the browser at runtime, not the actual source of the page.
Let's say for the sake of argument that using .html()
actually could change the actual source of the page, don't you think this might raise a security concern or two? Or three?
The answer is no, you cannot change the source of a web page from JavaScript without first tunneling through the server side via Ajax or other means.
View Source gives You the source of the page that was initial to all changes by jquery the dynamic changes are reflected in the generated source chk out the Web Developer plugin for firefox
Edit : https://addons.mozilla.org/en-US/firefox/addon/60/
view source > view Generated source
View source pulls the results directly from the server and does not run any javascript.
Therefore your .html() call did not get run.
'View Source' always shows the HTML source of the file when it was downloaded originally. Updates via jQuery/Ajax will never show up there.
View source feature give you source in html who they obtained from server he not show you changes even if you update and modified the content using ajax or jquery
but you can also find out changes by plugin or add-ons like Firebug or Web Developer.
the source you see using View source not show you all changes who you made by jquery or ajax. he just show you content who they obtain from server.
精彩评论