javascript - How to call a script embedded into a HTML element -
javascript - How to call a script embedded into a HTML element -
having next html
:
<div id="plugin"> <script> (function(){ this.do = function(e){ alert("cool!"); }; }); <script> <div>
how phone call this.do
(say parent element click button event handler)?
maybe more info help advising on right solution. it's plugin, want both markup , script part of same file. want able like:
$("#plugin").*controller*.do();
outside of plugin.
here's candidate solution, inspired scott's answer:
<div> (function(){ var plugin = $("#plugin"); plugin.do = function(e){ alert("cool!"); }; }); </div>
then outside:
$("#plugin").do();
any issues it?
why against doing?
<script> function do(){ alert('cool!'); } <script>
you :
<script> window.do = function(){ ... } </script>
then else:
window.do()
javascript html dom
Comments
Post a Comment