How to access elements in <script> inside body tag

I am using <script>

inside the body tag.

<script type="text/javascript" language="javascript">
 $('#audioVolume').text($('#audioVolume').text(Math.round((document.mediaPlayer.Volume + 2000) / 10) + "%"));
</script>

      

Error: Microsoft JScript Runtime Error: 'undefined' is null or not an object.

Necessity: I want to access html elements in <script

inside the body tag.

+2


a source to share


2 answers


The best guess is document.mediaPlayer

undefined. I think you have a typo too - are you setting the element text as a result of setting the element text? Try to wrap the whole thing inside a finished function so that it doesn't run before the DOM is loaded. If that doesn't work, run the debugger tools in IE8 and see which element is undefined.



<script type="text/javascript" language="javascript">
 $(function() {
     $('#audioVolume').text(Math.round((document.mediaPlayer.Volume + 2000) / 10) + "%"));
 });
</script>

      

+4


a source


<script type="text/javascript" language="javascript">
$(document).ready(function(){
 $('#audioVolume').text(Math.round((document.mediaPlayer.Volume + 2000) / 10) + "%");
});
</script>

      



0


a source







All Articles