0

I'm trying to make it so that there is a default tab, and when another is clicked, it takes the class off of that tab and onto the one that is clicked.

Here's the HTML that I have:

<div id="rightWrap">
    <div id="headStep"><span class="titleSub">Workers</span></div>
    <center>
    <br>
    <a href="../about/?s=architect"><table class="highlight">
    </table></a>
    <br>
    <a href="../about/?s=broker"><table class="">
    </table></a>
    <br>
    <a href="../about/?s=operator"><table class="">
    </table></a>
    <br>
    <a href="../about/?s=consultant"><table class="">
    </table></a>
    </center>
</div>

And the JavaScript:

$(document).ready(function() {
    $('#rightWrap a table').click(function(){
    $(this).addClass('highlight').siblings().removeClass('highlight');
});
});
0

2 Answers 2

4

Your tables are not siblings.

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

Note that if the doctype of the page is not HTML5, wrapping the tables with <a> elements makes your document invalid.

Sign up to request clarification or add additional context in comments.

3 Comments

@JohnConde Thanks for the edit, but there is no difference between the edited code and the original one.
In HTML5, it's perfectly legal to wrap a block level element (like a table) with an <a> tag and many browser have allowed this for awhile. The empty tables are what make no sense to me.
@jfriend00 Yes, I know it's legal in HTML5, I think table tags have their on markup and OP hadn't posted them for brevity.
1

I think you can simplify it to this;

$(document).ready(function() {
    $('#rightWrap a table').click(function(){
        $('#rightWrap').find('.highlight').removeClass('highlight');
        $(this).addClass('highlight');     
    });
});

Your HTML also needs some serious work. Why the empty tables?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.