tags:

views:

26

answers:

2

I have an ASP.NET reportviewer in a page whose width (a div width) I am trying to determine. I have the test code below. The first alert returns the proper client id. I can see the div in the html source. I can see its width in FireBug. However the second alert returns null. The syntax looks fine. Why is it returning null?

<script type="text/javascript" src="includes/jquery-1.4.2.min.js"></script>
<script type="text/javascript" language="javascript">
alert('<%=rvMain.ClientID %>');
alert( $('#<%=rvMain.ClientID %>').width() );

</script>
+1  A: 

Have your elements loaded at the time that javascript fires? Try using a document.ready call and see if you get the same result.

rosscj2533
I forgot the ready function.
Tony_Henrich
+3  A: 

Are you wrapping that code in $(document).ready(function () { /* code */ });? If not, you may be trying to reference an element that doesn't yet exist in the DOM.

Russ Cam