Quantcast
Viewing all articles
Browse latest Browse all 13965

[[qanda:topic_unsolved]] How to use getElementsByClassName with WebEngine runJavascript

Hello,
I'm having a problem modifying the content of HTML document using getElementByClassName or getElementById. My code is not generating error except when there is an error in the code, but it's not working either. Here is the relevant part of my code that is not working:

WebEngineView {
       id: webviewer
       anchors.fill: parent
       url: "https://developer.mozilla.org/en-US/"
       opacity: 1
       visible: true
}


Connections {
   target: webviewer
       onLoadingChanged: {
   	if (WebEngineLoadRequest.LoadSucceededStatus)
   		webviewer.runJavaScript("var Elem = document.getElementsByClassName('highlight-span'); Elem.innerHTML = 'Hello!'";)
}

But when I target a specific HTML element with 1 line of code, it works.

webviewer.runJavascript("document.body.innerHTML = 'Hello!' ")

Is it that runJavascript doesn't understand 2 lines of code? Or getElementsByClassName?
Please what am I doing wrong here?


Viewing all articles
Browse latest Browse all 13965

Trending Articles