Is there a JQuery equivalent of ASP.Net Ajax's $find() function?
$() != $find()
Is there a JQuery equivalent of ASP.Net Ajax's $find() function?
$() != $find()
There is not a 1to1 equivalent but what you want is $('selector')
Check out the docs on the different selectors
$find('MyComponent') would be $('#MyComponent')
$find('MyComponent',div) would be $(div).find('#MyComponent')
If you want to find an element by its ASP.NET code ID rather than the generated ClientID (ctl00_RealId
) then you can use this function. It just looks for elements that have an ID that ends with _{the real ID here}
:
var $$ = function (id, context) {
var $ = (jQuery) ? jQuery : return ;
var el = $("#" + id, context);
if (el.length < 1)
el = $("[id$=_" + id + "]", context);
return el;
}
For example, say your ID in your code is pnlSuccess
, say a panel:
<asp:Panel ID="pnlSuccess" runat="server"></asp:Panel>
But in the rendered code it comes out as: ctl00_content_ctl00_pnlSuccess
calling $$("pnlSuccess")
will find that rendered panel.
I'd just do the following, no muss, no fuss, straight to the point.
$('#' + <%=myControl.ClientID%>)