How to read an ID from a DIV, and put in a VAR?

1

Friends,

In my page, with this DIV listed below, I would need to "read" the id that is in the < the id="memo-list-delete-6_2544_0"> or the value "memo-list-delete-6_2544_0" and put in a variable to use later .. like do this with JS?

    <div id="memo-list-6">
        <i>Testo 00</i>
        <pre> Texto 01 </pre>
        <a id="memo-list-delete-6_2544_0" >
            <span class="UmaClasse">    </span>
        </a>
    </div>

I tried to do:

var MinhaInfo = document.querySelectorAll('#memo-list-6 a').length;

but it only returns a number ...

    
asked by anonymous 25.03.2016 / 07:23

1 answer

3

I think this would be Roberval:

var MinhaInfo = $('#memo-list-6 a').attr('id');

And just as a good practice tip, always try to use the naming convention for variables in whatever language you are programming. To javascript the default is camelCase .

Basically camelCase says that the first word of the variable will always begin with a lowercase letter and from there the words begin with capital letters. Examples:

var minhaInfo = 1;
var minhaVariavelManeira = 2;
var variavelPadraoCamelCase = 3;
var camelCase = 4;
    
25.03.2016 / 07:27