Jaso2970
Jaso2970

Reputation: 147

How to apply a style to a table which has the Border property with jQuery?

I have 2 tables and want (using jQuery) to add the class: border-width-1 to all td elements to the table which border property is not 0. In the example below this code would add the class: border-width-1 to all td elements in table id="table-1"

    Having these tables 
        <table border="1" id="table-1">
        <tr>
        <td>row 1, cell 1</td>
        <td>row 1, cell 2</td>
        </tr>
        </table>

           <table border="0" id="table-2">
            <tr>
            <td>row 1, cell 1</td>
            <td>row 1, cell 2</td>
            </tr>
            </table>

        After execution this would be the results: 
            <table border="1" id="table-1">
            <tr>
            <td class="border-width-1">row 1, cell 1</td>
            <td class="border-width-1">row 1, cell 2</td>
            </tr>
            </table>

I don't know how to target a element property with jquery. That's why I can't begin to write a function.

Upvotes: 0

Views: 134

Answers (1)

kidwon
kidwon

Reputation: 4524

That is your code:

   jQuery('table[border!="0"] td').addClass('border-width-1');

Upvotes: 1

Related Questions