Solved

best way to replace content within span id

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
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…

920 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

13 Experts available now in Live!

Get 1:1 Help Now