Solved

best way to replace content within span id

Posted on 2008-06-25
3
795 Views
Last Modified: 2008-06-26
Hi folks. I'm looking for the best way to replace the content within the following:
<span id="QueryScreenControl1_lblPageHeader" class="query_tblheader" style="width:712px;">Some Name: Catalog</span>
so that what displays is only:  Catalog
I've executed the attached code, but need something that will work more broadly. For instance, let's say I've got the following: <span id="QueryScreenControl1_lblPageHeader" class="query_tblheader" style="width:712px;">Some Name: Serials</span>
then I want to end up displaying only:  Serials.
Or suppose I have the following: <span id="QueryScreenControl1_lblPageHeader" class="query_tblheader" style="width:712px;">Some Name: Something Else</span>
then I want to end up with:  Something Else
Perhaps I should use innerHTML.replace and a RegEx? Please advise. Am looking for a good solution that doesn't require multiple "ifs" and "thens"

if(document.getElementById("QueryScreenControl1_lblPageHeader") !=null) {

   if(document.getElementById("QueryScreenControl1_lblPageHeader").innerHTML=="Some Name: Catalog") {

      document.getElementById("QueryScreenControl1_lblPageHeader").innerHTML = "Catalog"

      }

}

Open in new window

0
Comment
Question by:GessWurker
  • 2
3 Comments
 
LVL 11

Accepted Solution

by:
JohnSixkiller earned 500 total points
ID: 21872242
Hi,
try this:

var span = document.getElementById("QueryScreenControl1_lblPageHeader");
if(span != null && span.innerHTML.indexOf(": ")>-1) span.innerHTML = span.innerHTML.substring(span.innerHTML.indexOf(": ")+2);

0
 

Author Comment

by:GessWurker
ID: 21874750
John: Works perfectly! Thanks. Points to you! I've got a closely related question on the way.
0
 
LVL 11

Expert Comment

by:JohnSixkiller
ID: 21875840
You are welcome and thanks for the points.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…

707 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

12 Experts available now in Live!

Get 1:1 Help Now