Solved

best way to replace content within span id

Posted on 2008-06-25
3
799 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
[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
  • 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Title # Comments Views Activity
JavaScript Loan Calculator Error 3 35
jQuery Datatables.js Selecting a Row to get ID 5 37
Date on a table 16 35
Word Press Fixes to Google Speed Test Issues 2 25
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

733 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