Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
24
rated 0 times [  26] [ 2]  / answers: 1 / hits: 56694  / 13 Years ago, sat, august 13, 2011, 12:00:00

Support that I have this hidden field:



<input type='hidden' id='handler' name='handler' value='5534882394' />


And imagine that I fetch an HTML fragment from server via jQuery AJAX.



<div id='result'>
<span></span>
</div>


However, instead of writing something like this:



$(function(){
$('#result span').text($('#handler').val());
});


I'd like to use something like:



<div id='result'>
<span>javascript:$('#handler').val();</span>
</div>


However, I don't get the intended result. Can I use this approach with JavaScript?



Update: Everybody please, I know about $(document).ready();. So, don't provide better ways. I just wanted to know if it's possible to have inline JavaScript, or not, and if yeah, how?


More From » jquery

 Answers
106

No, you can't use that approach with Javascript. There is no such thing as inline Javascript.



What you see in a link like <a href=javascript:alert(1)> is the javascript: pseudo-protocol, similar in use to the http: protocol. When you point the browser to such an URL, the browser runs the script.



If you want to run a script in the page, you need a script tag.


[#90631] Friday, August 12, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
alejandro

Total Points: 231
Total Questions: 102
Total Answers: 107

Location: Jordan
Member since Wed, Jun 17, 2020
4 Years ago
alejandro questions
Mon, Jul 18, 22, 00:00, 2 Years ago
Fri, Sep 18, 20, 00:00, 4 Years ago
Thu, Sep 10, 20, 00:00, 4 Years ago
;