Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

best way to replace content within span id

Posted on 2008-06-25
3
Medium Priority
?
802 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 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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…

610 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