Solved

best way to replace content within span id

Posted on 2008-06-25
3
798 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

839 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