How can I find out that an element is what <script> sits in?
As an example, take this
<div> <script type="text/javascript"> var time = new Date(), hrs = time.getHours(), min = time.getMinutes(); document.write('It is '+hrs+":"+(min<10?'0':'')+min); </script> </div>
Then, if I want to change this to something more modern, how can I find out which element we are in?
Therefore, I want to write, for example, in jQuery
$(thisdiv).html('It is '+hrs+":"+(min<10?'0':'')+min);
but how do i get thisdiv ?
Yes, I know, I can put an ID on him, but I have the feeling that it would not be necessary. The browser knows where we are, otherwise it could not even have done document.write!
So suggestions? I searched, but could not find it. Is it that simple that I don't notice the obvious?
javascript dom this
Mr Lister Feb 09 '12 at 11:11 2012-02-09 11:11
source share