Solved

trying to get a better way to do it jquery

Posted on 2013-12-18
2
210 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
Question by:myselfrandhawa
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 15

Author Closing Comment

by:myselfrandhawa
ID: 39726256
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

705 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now