Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

174
Vistas
How to access a value which is defined inside a div using jQuery

How can we access a value which is defined inside the element? I tried this code, but it's not working.

$(document).ready(function() {
  console.log($("div#named").val());
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<div id="named" Items='10'>Hello World!!</div>

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Assuming by 'value' you mean the 'Items' attribute, then use attr():

jQuery($ => {
  console.log($("div#named").attr('Items'));
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<div id="named" Items="10">Hello World!!</div>

However you should note that Items is not a standard HTML attribute and will cause your HTML to be invalid.

The correct way to add any metadata to an element is to use a data attribute instead. You can then read this using jQuery's data() method:

jQuery($ => {
  console.log($("div#named").data('items'));
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<div id="named" data-items="10">Hello World!!</div>

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda