Get HTML tag in where Javascript is included -


this question has answer here:

here html:

<div>      hello text      <script src="/javascript.js" ></script> </div> 

and in javascript.js, want height , width of the div javascript.js included.

i found how id:

document.getelementbyid('foo').offsetwidth; 

but how reference div javascript.js included?

you cannot refer div in javascript.js file directly. however, can div id on document load , sctore in global variable future use.

 var mydiv = []    $(document).ready(function(){       $('script').each(function(){         mydiv.push($(this).parent('div'))               })  } ) 

Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -