13,199,026 members (39,597 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
 OriginalGriff 370 ppolymorphe 120 Richard MacCutchan 35 CPallini 30 Karthik Bangalore 25
 OriginalGriff 7,745 ppolymorphe 1,934 Karthik Bangalore 1,654 CPallini 1,100 Jochen Arndt 1,055