Solved

trying to get a better way to do it jquery

Posted on 2013-12-18
2
220 Views
Last Modified: 2013-12-18
I am doing like this:

Is there a better way to this, a lot of check conditions are, like if i can use something like each and one liner could do

http://jsfiddle.net/BsfZF/
0
Comment
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 44

Accepted Solution

by:
Rainer Jeschor earned 500 total points
ID: 39726105
Hi,
a more generic way would be:
- Extend the li elements by using a custom data attribute
- Use the above attribute to set the classes

HTML:
<div>
    <ul>
        <li class="display" id="ID1" data-switch="class0,class1">Data 1</li>
        <li class="display" id="ID2"data-switch="class2">Data 2</li>
        <li class="display" id="ID3" data-switch="class3">Data 3</li>
    </ul>
</div>
<table>
<tr>
    <td class="class0">&nbsp;</td>
    <td class="class1">abc</td>
    <td class="class2">xyz</td>
    <td class="class3">xyzx</td>
</tr>
<table>

Open in new window

Script:
$(document).ready(function() {
    $('div ul li.display').click(function() {
        var li = $(this).attr('data-switch').split(",");
        $.each(li, function(key,value) {
            $("." + value).toggleClass("hidden hideBorder");
        });
    });
});

Open in new window

Online sample:
http://jsfiddle.net/EE_RainerJ/rv2ys/

HTH
Rainer
0
 
LVL 16

Author Closing Comment

by:Gurpreet Singh Randhawa
ID: 39726256
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question