Solved

Collapsible text - different image for background when opened?

Posted on 2011-09-15
13
303 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 11

Author Comment

by:Amanda Watson
Comment Utility
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
Comment Utility
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
Comment Utility
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 11

Author Comment

by:Amanda Watson
Comment Utility
the url is correct
0
 
LVL 40

Expert Comment

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

Author Comment

by:Amanda Watson
Comment Utility
Thank you
0
 
LVL 11

Author Closing Comment

by:Amanda Watson
Comment Utility
Thank you so much
0
 
LVL 11

Author Comment

by:Amanda Watson
Comment Utility
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
Comment Utility
thanks for the points...glad to help
0
 
LVL 11

Author Comment

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

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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 …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

743 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now