Solved

Javascript replace text string with h3

Posted on 2015-01-13
1
208 Views
Last Modified: 2015-01-17
Hi,

Using Chrome Dev Tools I have found the CSS selector of a H3 heading.

#container > div.my-table > h3

Open in new window


Within the H3 heading is "Test - some more text here". I need to replace "Test" with "New".

The following attempt results in an 'undefined' error message -

document.body.innerHTML = document.querySelector('#container>div.my-table>h3').replace("Test", "New");

Open in new window


Can anyone see what I am doing wrong?
0
Comment
Question by:mhdi
[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
1 Comment
 
LVL 9

Accepted Solution

by:
sudheeshthegreat earned 500 total points
ID: 40547985
document.querySelector('#container>div.my-table>h3')
just returns the DOM object. You need to get to this object's text first before attempting to replace it.

Try this:
var theH3Node = document.querySelector('#container>div.my-table>h3');
theH3Node.innerHTML = theH3Node.innerHTML.replace("Test", "New");
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
The viewer will learn how to count occurrences of each item in an array.
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)

635 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