have to obtain the numeric value of a tag without being by id, in case a class and then divide by another number and show inside the site

Asked

Viewed 17 times

-1

I want to do an extension for Chrome, the idea is to take a numeric value from inside a site, on its page and make count adding, subtracting, dividing and etc and then show the result next to the value as a little calculator I tried a few things and got by Id, but when the tag is a class I’m not getting:

here the manifest

{
    "manifest_version": 2,
    "version": "0.0.1",
    "name": "test calc",
    "description": "calc",
    "author": "LA",
    "browser_action": {
     "default_title": "Alterando valor",
     "default_popup": "index.html",
     "default_icon": "icon.png"

 },
 "content_scripts":[
 {
 "js": [ 
 "captura.js"
 ],
 "matches": [
 
 "https://sitequalquer/*"
 ]
 
 }
 
 ]
   
}

and here the javascript

var url = document.getElementById('Idtal').text;
alert(url);

var url = document.getElementsByClassName('classetal').innerText;
alert(url);

var url_ = document.getElementsByClassName('classetal')[0].innerHTML;
alert(url_);

var url_ = document.getElementsByClassName('classetal')[0].value + ",";
alert(url_);

another question is: after I need to use an operator with var and send by Alert, correct?

1 answer

0

The getElementsByClassName returns an array and the object containing its text is textContent, see this example.

var url = document.getElementById('this-id').textContent
alert(url);

var url = document.getElementsByClassName('class-name')[0].textContent
alert(url);

How much your other doubt: you can do this:

var a = 5;
alert(a + 45); //output: 50
  • wow, thank you so much Felipe Chagas worked really well was that & #Xa;thank you really =D

  • You’re welcome! If you killed the doubt, you can mark it as a solution, to close the question, please.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.