Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Collapsible text - different image for background when opened?

Posted on 2011-09-15
13
Medium Priority
?
313 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:Gurvinder Pal Singh
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:
Gurvinder Pal Singh earned 2000 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
Technology Partners: 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:Gurvinder Pal Singh
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:Gurvinder Pal Singh
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:Gurvinder Pal Singh
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

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!

Question has a verified solution.

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

Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
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

773 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