12,549,311 members (47,636 online)
Rate this:
See more:
I have to change the button text on its click alternatively using jquery on aspx page. I have used the below code for this. But the else part doesn't work.

```\$(function () {
\$("#<%=btnSearch.ClientID %>").click(function () {
\$("#dv").slideToggle(500);
if (\$(this).text("Hide Selection Criteria")) {
\$(this).html('Show Selection Criteria');
}
else {
if (\$(this).val() = "Show Selection Criteria") {
\$(this).html('Hide Selection Criteria');
}
}
return false;
});
});```
Posted 26-Mar-12 20:02pm

Rate this:

## Solution 2

```var x = 1;
\$(function () {
\$("#<%=btnSearch.ClientID %>").click(function () {
\$("#dv").slideToggle(500);
if ((x % 2) != 0) {
\$(this).text('Show Selection Criteria');
x++;
}
else {
\$(this).html('Hide Selection Criteria');
x++;
}
return false;
});
});```
Rate this:

## Solution 1

Try this code.
Use \$(this).val() instead of if (\$(this).text("Hide Selection Criteria")

```\$(function () {
\$("#<%=btnSearch.ClientID %>").click(function () {
\$("#dv").slideToggle(500);
if (\$(this).val() == "Hide Selection Criteria") {
\$(this).html('Show Selection Criteria');
}
else if (\$(this).val() == "Show Selection Criteria") {
\$(this).html('Hide Selection Criteria');
}
return false;
});
});
```
Member 8514528 27-Mar-12 2:17am

now I have used below code even then the else part not working.

\$(function () {
\$("#<%=btnSearch.ClientID %>").click(function () {
\$("#dv").slideToggle(500);
if (\$(this).val("Hide Selection Criteria")) {
\$(this).html('Show Selection Criteria');
}
else {
\$(this).html('Hide Selection Criteria');
}
return false;
});
});

Top Experts
Last 24hrsThis month
 Tadit Dash (ତଡିତ୍ କୁମାର ଦାଶ) 60 manu_dhobale 45 Dave Kreskowiak 30 Peter Leow 25 Mika Wendelius 20
 OriginalGriff 3,902 Suvendu Shekhar Giri 1,713 John Simmons / outlaw programmer 1,687 ppolymorphe 1,546 Karthik Bangalore 1,210