Difference Between '$(<%= Ddl.id %>) & $('<%= Ddl.id %>')
I was trying to bind an event to drop down list since yesterday nothing helped went to JavaScript chat room no one was able to find a fix to my problem, but then I somehow tried to
Solution 1:
jQuery uses CSS selector
like syntax.
For ID Selector
it needs to be prefix with #
symbol. Example, $('#DOMElementId')
Check jQuery Selector list
In your case correct one should be
$('#<%= ddl.ID %>').bind('change',myfunction) // if you have no master page or //ClientIDMode="static"
or
$('#<%= ddl.ClientID %>').bind('change',myfunction)
Solution 2:
The jQuery function needs a string as selector.
The latter syntax has no meaning, except
- if your string is a javascript variable (for example
document.body
ormyvar
if you definedmyvar
). - if your
ddl.ID
string contains the quotes (you may have created it asddl.ID = "\"#id\"";
)
It's possible you fixed a bug by another bug rendering ineffective this line in your code.
Solution 3:
You should probably use ClientID
instead
$('#<%= ddl.ClientID %>').bind('change', myfunction);
Solution 4:
best option is
$('#'+'<%= ddl.ClientID %>').bind('change',myfunction);
it works even you use this control in user control or content page
$('#'+'<%= ddl.ClientID %>').change(myfunction);
Post a Comment for "Difference Between '$(<%= Ddl.id %>) & $('<%= Ddl.id %>')"