Reputation: 544
I did a small style changing app using Jquery in Asp.Net 3.5 .I am having IE7. When i click on button the paragraph color should change. Problem is ,the color is changing,it is not stable.Means just like blinking. Please find the code below
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript" src="scripts/jquery-1.4.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#Button1").click(function() {
$("p").css("background-color", "Yellow")
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Button" />
<p>This Should be in <br/>
yellow</p>
</div>
</form>
</body>
</html>
Upvotes: 0
Views: 124
Reputation: 1968
$("input[id$='Button1']").click(function() {
button click stuff here.
});
Upvotes: 0
Reputation: 120518
Change:
$("#Button1").click(function() {
to
$("#<%=Button1.ClientID%>").click(function() {
Upvotes: 0
Reputation: 794
try this :
$("#<%=Button1.ClientID %>").click(function() {
$("p").css("background-color", "Yellow")
});
When the Button renders on the client it won't have id = "Button1"
Upvotes: 1
Reputation: 191048
Its because ASP.NET changes the ID attribute to be something it can resolve.
If you are using ASP.NET 4, set the ClientIDMode
to AutoID
.
If you are using anything else, change your selector to use "#<%= Button1.ClientID %>"
Also, return false
to prevent the form from being postbacked.
Upvotes: 2