Unable to retrieve offset for a ASP.NET server-side control

157 Views Asked by At

I'm trying to retrieve the offsetHeight of a server-side control but it gives me an error. Here's the following code snippet -

  function Test() {
            var imgFavorite = $("<%= imgFavorite.ClientID %>"); //imgFavorite is a server-side asp:Image control.
            alert(imgFavorite); //[object Object]
            alert(imgFavorite.offsetHeight()); //undefined.    
   }

What is wrong with the code?

1

There are 1 best solutions below

1
On BEST ANSWER

You've missed the hash when declaring the jQuery object using an ID:

var imgFavorite = $("#<%= imgFavorite.ClientID %>");