简体   繁体   中英

Changing tabs with jQuery

I'm attempting at changing the background color of the td's on click. This is what I currently have for JavaScript:

$(document).ready(function() {
$('#leftHoldNav table td').click(function(){
    var $this = $(this);
    $this.addClass('highlight');
    $this.parent().siblings('table').find('td').removeClass('highlight');
});
});

This is what I have for the HTML:

    <div id="leftHoldNav">
    <center>
    <table cellpadding="0" cellspacing="0">
    <tr>
        <td onclick="loadPage('../about/info.php','#mainWrapLoad','../about/')" class="highlight">Info</td>
        <td onclick="loadPage('../about/kcintl.php','#mainWrapLoad','../about/')" class="">KC Int'l</td>
        <td onclick="loadPage('../about/board.php','#mainWrapLoad','../about/')" class="">Board</td>
        <td onclick="loadPage('../about/dcon.php','#mainWrapLoad','../about/')" class="">D-Con</td>
    </tr>
    </table>
    </center>
    </div>

It's not working, anybody have an idea why?

http://jsbin.com/inogov/1/edit

you don't need to go back to parent , stay on the siblings .

$this.siblings('td').removeClass('highlight');

There you go:

$('#leftHoldNav table td').click(function(){
    var $this = $(this);
    $this.addClass('highlight').siblings('td').removeClass('highlight');
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM