Zaki
Zaki

Reputation: 5600

Change class using jquery

I have a td with follwoing class named 'rgExpandCol' and want to change the class of input inside it. below is my html:

<tr>
    <td class="rgExpandCol">
    <input class="rgExpand" ...
    </td>
<tr>

and I have tried this jquery but I get $find is null:

$(this).closest('td').attr('rgExpand', 'rgCollapse');

EDIT :::

basically am using radgrid and expanding rows which are hidden using

$(this).closest('tr').next('tr').css('display', '');

and $(this) is on my click event of grid as so

$("#<%=gv.ClientID%> tr:has(td)").click(function (e) { 

Upvotes: 0

Views: 333

Answers (6)

Jay Blanchard
Jay Blanchard

Reputation: 34426

Use removeClass() and addClass() to make the change.

$("#<%=gv.ClientID%> tr:has(td)").click(function (e) {
    e.preventDefault();
    $(this).find('input').addClass('rgExpand').removeClass('rgCollapse');
});

Assuming that the id used in the selector identifies the table.

Upvotes: 0

Sajjan Sarkar
Sajjan Sarkar

Reputation: 4198

$(this).closest('td').find("input").removeClass("old").addClass("new")

Will apply the CSS for inputs inside the TD :)

Upvotes: 1

gbelorgey
gbelorgey

Reputation: 31

First you need to select the input, which can ben done with a single selector :

var my_input = $(this).find('input.rgExpand');

Then you can remove its current class and add the new one :

my_input
    .removeClass('rgExpand')
    .addClass('rgCollapse');

Upvotes: 2

fso
fso

Reputation: 154

$('tr td.rgExpandCol input.rgExpand').removeClass('oldClass').addClass('newClass');

Upvotes: 1

dahliacreative
dahliacreative

Reputation: 441

So you want to target the td and change the class of the input inside it?

I'd do this:

$('.rgExpandCol > input').removeClass('classtoremove').addClass('newclasstoadd');

Upvotes: 0

War10ck
War10ck

Reputation: 12508

Try this:

$('.rgExpandCol > input').removeClass("< existing class >").addClass("< new class >");

Upvotes: 0

Related Questions