Solved

show/hide icons on click jquery

Posted on 2010-11-16
9
665 Views
Last Modified: 2012-05-10
Hi experts.

In our application,we have a menu with 18 navigation icons so I am trying to hide some of the icons and toggle on click of a button. I have found a jquery script which I like but the script works with divs and I want it to work on  'TD' as each icon is in a single TD in my code .
I have attached 3 files
1. the show/hide script
2. my code
3.screenshot  

 toggle.html
 mycode.html
screenshot.jpg
0
Comment
Question by:vravi22
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 13

Expert Comment

by:stergium
Comment Utility
have you tried giving the specified td an id and/or a class.  jquery works with css selectors (besides other things) . so you modify

$("#showr").click(function () {
  $(".CLASS").show("fast", function () {  /*or #id of td you want to hide show*/
    /* use callee so don't have to name the function */
    $(this).next("div").show("fast", arguments.callee);
  });
});
$("#hidr").click(function () {
  $("div").hide(2000);  /* .class or #id you want to show/hide
});
</script>
0
 
LVL 13

Expert Comment

by:stergium
Comment Utility
i've have modified toggle.html so you can study it and suit it to your needs
toggle.html
0
 
LVL 3

Expert Comment

by:boraganesh
Comment Utility
hi,

you can modifiy the anachor elemet. insted of div use it as td.
$("div")==> $("td")
0
 
LVL 19

Accepted Solution

by:
Bardobrave earned 250 total points
Comment Utility
Or even easier... you can get a DIV inside your TDs, if you wrap each of your images inside a div you won't need to change the jquery code
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Expert Comment

by:cgt_puneetrao
Comment Utility
First I suggested you to use div instead of td. but still if you want to use td then you can use the code I have attached.
mycode.html
jquery-1.4.2.min.js
0
 
LVL 3

Expert Comment

by:boraganesh
Comment Utility
only change the anachor to td insted of div.
and dont touch the any other html code. its the simplest way to make it work.
0
 

Author Comment

by:vravi22
Comment Utility
@Bardobrave : thanks a lot .that was the simplest and most effective solution . I just have one small problem .by default it is hidden because of the css used
<style>
  div { background:#def3ca; margin:3px; width:80px;
  display:none; float:left; text-align:center; }
  </style>

if i use it in my page,it will hide the entire page so  
how do i change it so that it hides only some icons and not the entire page .?
0
 
LVL 19

Expert Comment

by:Bardobrave
Comment Utility
There are different solutions to this, depending on what do you want to do and how to make it.

What I would probably do will be the following:

Give my wrapping divs a class, say "hideable".

On the css file apply the styles only to those class divs

.hideable { background:#def3ca; margin:3px; width:80px;
  display:none; float:left; text-align:center; }

If you want your divs to don't be hidden by default you can change the display:none to display:block, surely jquery will manage the show/hide effect in an independent way from the starting situation.

If you want some icons active by default, some other inactive by default and that every icon can be hided you can play with two different classes, one for hidding and another for showed, and change your jquery to swap the class of the clicked div
0
 
LVL 3

Expert Comment

by:boraganesh
Comment Utility
to apply the jqueryeffect the requried selected tags.

follow the follwoing methode of using selector..
what ever contents to be required to hide put inside the one div called this div as name id=myeffectdiv
then inside this div add separate td tags for each elememt..waht you have presently

then in jquery use selector which will apply the effect to the td's present inside the div id id=myeffectdiv

 
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
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)

728 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

14 Experts available now in Live!

Get 1:1 Help Now