Click here to Skip to main content
15,937,861 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This is webform1 code where i call a javascript function on button click

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="valid_try2.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script type="text/javascript" src="JavaScript1.js"></script>

<title></title>
</head>
<body>
<form id="form1" runat="server">


<button id="btn" class="xx" name="btn" onclick="abc()">Button</button>

</form>
</body>
</html>


This is stylesheet file for css
.xx {
border: 5px solid green;
}

.yy {
border: 5px solid red;
}

This is javascript file

function abc() {
$("#btn").removeClass("xx");
$("#btn").addClass("yy");
}

What I have tried:

i want to change the class after button click but i am not do this plz help me kindly
Posted
Updated 15-Oct-16 22:56pm

1 solution

Hello

The best way is ti using Javascript / jQuery:

JavaScript
$(document).ready(function(){
  $('#Your_Button_ID').on('click', function(){
      $('button').removeClass('Old_CSS_Class');
      $(this).addClass('New_CSS_Class');
});


for useful examples please see:

W3Schools
StackOverFlow
ASP.Net

Best Regards
 
Share this answer
 
Comments
Ali Majed HA 16-Oct-16 5:09am    
Please have a look at 3rd Link. It has been using asp.net
Ali Majed HA 16-Oct-16 5:11am    
I am not well trained in server-side languages and technologies like asp.net.
sorry if it does not work
Member 12107284 16-Oct-16 5:46am    
sir i add this but change was not remain continues ...little time apply and again change to firstclass
Member 12107284 16-Oct-16 5:47am    
bundle of thanks
Ali Majed HA 16-Oct-16 6:27am    
If it works, would you please accept and vote answer? Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900