Solved

Collapsible text - different image for background when opened?

Posted on 2011-09-15
13
306 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
  • 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
This article discusses how to create an extensible mechanism for linked drop downs.
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…

778 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