Ajay Ajay - 9 months ago 39
jQuery Question

find value of id in jquery

when I am trying to fetch the value of id, it returns me 0; I want "a".
Thanks in ADVANCE

$(document).ready(function() {
var a = $('#lettera').val();console.log(a);
<div class="container">
<div class="row">
<ul class="list-inline">
foreach($alphas as $letter){
echo ($this->Html->tag('li', $letter, ['id' => 'letter'.$letter]));

Answer Source

The element you're creating appears to be an li, and li don't have a value attribute. Presumably you're looking for the text of the element, so use text() instead:

  var a = $(this).text();