Solved

Collapsible text - different image for background when opened?

Posted on 2011-09-15
13
308 Views
Last Modified: 2012-05-12
Hi There,
I have just found this great script
http://javascript.internet.com/miscellaneous/collapsible-text.html

I have used it on my site, the only thing I am missing is...when you click on the text, I want the background image of the title to change.
So for example you have an arrow point > to indicate you can click on the text, and then once its clicked and opened, the arrow points V   - can anyone help me achieve this?

Thanks in advance
0
Comment
Question by:Amanda Watson
[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
  • 8
  • 5
13 Comments
 
LVL 40

Expert Comment

by:gurvinder372
ID: 36547461
document.getElementById("elementWithTextId").onclick = function(){
   this.style.backgroundImage = "url('imageURL')";
}

http://www.w3schools.com/jsref/prop_style_backgroundimage.asp
0
 
LVL 11

Author Comment

by:Amanda Watson
ID: 36547489
Hi,
Thanks for the reply
how can I incorporate this into the javascipt I am using

// JavaScript Document
/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Sandeep Gangadharan | http://www.sivamdesign.com/scripts/ */
if (document.getElementById) {
  document.write('<style type="text/css">.texter {display:none; border-left:white 20px solid; color:#404040; font: .9em verdana, arial, helvetica, sans-serif; margin-bottom: 12px;}</style>') }

  var divNum = new Array("a1","a2","a3");  // at the left you should add a1, a2 etc. for each header you wish to include
                                          // so if you want 4 headers you should add a1, a2, a3, a4 in the format shown
                                          // enclosed in double quotes
function openClose(theID) {
  for(var i=0; i < divNum.length; i++) {
    if (divNum[i] == theID) {
      if (document.getElementById(divNum[i]).style.display == "block") { document.getElementById(divNum[i]).style.display = "none" }
      else {
        document.getElementById(divNum[i]).style.display = "block"
      }
  } else {
    document.getElementById(divNum[i]).style.display = "none"; }
  }
}

Open in new window

0
 
LVL 40

Accepted Solution

by:
gurvinder372 earned 500 total points
ID: 36547505
try this one
function openClose(theID) 
{
  for(var i=0; i < divNum.length; i++) 
  {
    if (divNum[i] == theID) {
      if (document.getElementById(divNum[i]).style.display == "block") 
      { 
            document.getElementById(divNum[i]).style.display = "none" ;
           document.getElementById(divNum[i]).style.background = "none";
      }
      else 
      {
           document.getElementById(divNum[i]).style.display = "block";
           document.getElementById(divNum[i]).style.backgroundImage = "url('imageURL')";
      }
  } else {
    document.getElementById(divNum[i]).style.display = "none"; }
  }
}

Open in new window

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 11

Author Comment

by:Amanda Watson
ID: 36547517
Hi again ok so this is my whole js scipt but it hasn't changed anything?
// JavaScript Document
/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Sandeep Gangadharan | http://www.sivamdesign.com/scripts/ */
if (document.getElementById) {
  document.write('<style type="text/css">.texter {display:none; border-left:white 20px solid; color:#404040; font: .9em verdana, arial, helvetica, sans-serif; margin-bottom: 12px;}</style>') }

  var divNum = new Array("a1","a2","a3");  // at the left you should add a1, a2 etc. for each header you wish to include
                                          // so if you want 4 headers you should add a1, a2, a3, a4 in the format shown
                                          // enclosed in double quotes
function openClose(theID) 
{
  for(var i=0; i < divNum.length; i++) 
  {
    if (divNum[i] == theID) {
      if (document.getElementById(divNum[i]).style.display == "block") 
      { 
            document.getElementById(divNum[i]).style.display = "none" ;
           document.getElementById(divNum[i]).style.background = "none";
      }
      else 
      {
           document.getElementById(divNum[i]).style.display = "block";
           document.getElementById(divNum[i]).style.backgroundImage = "url('http://qsd.ey3host.com/wp-content/themes/qsd/images/dentist.png')";
      }
  } else {
    document.getElementById(divNum[i]).style.display = "none"; }
  }
}

Open in new window

0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 36547536
please check the if the image URL is correct
Or better please show me the html page using this code
0
 
LVL 11

Author Comment

by:Amanda Watson
ID: 36547578
0
 
LVL 11

Author Comment

by:Amanda Watson
ID: 36547583
the url is correct
0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 36547603
In that link you have not updated the code in collapsibleText.js
0
 
LVL 11

Author Comment

by:Amanda Watson
ID: 36547609
Thank you
0
 
LVL 11

Author Closing Comment

by:Amanda Watson
ID: 36547612
Thank you so much
0
 
LVL 11

Author Comment

by:Amanda Watson
ID: 36547619
oops one thing sorry...but I wanted the top image to be replaced, the one with the arrow point >
0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 36547622
thanks for the points...glad to help
0
 
LVL 11

Author Comment

by:Amanda Watson
ID: 36547642
sorry I was just hoping that the background image would be replaced, not an image added to the content?
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

This article discusses how to create an extensible mechanism for linked drop downs.
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
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…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…

763 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