Solved

How do you toggle images for an on off state

Posted on 2014-01-23
3
239 Views
Last Modified: 2014-01-23
Hi,

I have some code (that works in JS Fiddle) but for some reason does not work when I put it on a web page.

I need the images to toggle from an on off state. But when you click on one of the images the other images need to turn off.

Here is my code and you can see what I'm talking about if you go to

http://thelocalized.com/matt/imagetoggle.html


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <link type="text/css" rel="stylesheet" href="style.css" />
  
  <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
  
  
  <script type="text/javascript">
  $(document).ready(function () {
   $("table a span").click(function(){
  $(this).toggleClass("on")
})
$("table a span:eq(0)").toggleClass("on")
  });
    </script>

  <title></title>
  <style>
  table a span {
    display:inline-block;
    height:20px;
    width:20px;
    border:1px solid blue
}
table a span.off {
    background:url("orange_off.png") red
}
table a span.on {
    background:url("orange_on.png") green
}
</style>
</head>

<body>
<table cellspacing="7" cellpadding="0" border="0">
	<tr>
	    <td width="60" align="left">View:</td>
        <td width="100"align="left"><a><span class="off"></span>All Types</a></td>
	    <td width="113" align="left"><a><span class="off"></span>On Demand</a></td>
		<td width="101" align="left"><a><span class="off"></span>Webinars</a></td>
		<td width="141" align="left"><a><span class="off"></span>Seminars</a></td>
        </tr>
        </table> 
</body>
</html>

Open in new window


Thanks!
0
Comment
Question by:smfmetro10
[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
3 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 39804453
You are using the first code sample from the other Q

$("table a span").click(function(){
    $("table a span").removeClass("on")
  $(this).toggleClass("on")
})
$("table a span:eq(0)").toggleClass("on")

Open in new window

0
 

Author Comment

by:smfmetro10
ID: 39804494
Yeah- I just cant get it to work on a webpage.
0
 

Author Closing Comment

by:smfmetro10
ID: 39804537
Wait- Sorry. I know what you're saying :)

Thanks!
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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 …
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…
Suggested Courses

623 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