Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Collapsible text - different image for background when opened?

Posted on 2011-09-15
13
Medium Priority
?
312 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: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
The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

 
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

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …

722 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