Extract value from a div tag

0

I'm trying to get a value like this

var pgr = $("#myProgress").val();
var mbar = $("#myBar").val();

Only that it returns empty to me "", if I do with the

var prg = document.getElementById("myProgress");

I get something like the following=" <div id="myBar" value="50" max="100" onclick="increase()"></div> "

Is there any way to get that variable prg out only the value?

All this is from a .js file

    
asked by Richard 08.05.2018 в 22:07
source

2 answers

1

Actually, DIV tags should not have "value" property as such, but instead be reserved for inputs, selects, form elements.

What you should do is put a "data-value" as indicated by the official HTML5 documentation, that is:

<div data-value="valor"></div>

Then you take this value in the following way with JQuery:

var valor = $('div').attr('data-value');

Any questions you have, you can comment.

Greetings!

    
answered by 08.05.2018 / 22:19
source
1

For pure javascript it is with .value , being of the following way:

var prg = document.getElementById("myProgress").value;

Remember that the .value or .val() of jQuery are only for the <input /> or <textarea></textarea> .

    
answered by 08.05.2018 в 22:09