-4

I have no idea what what to do. Actually i need id of the control(element/tag),

when key up on any control . if more attributes(name,style,etc) exist get all attribute values also.

thank you.

6 Answers6

4

According to jquery: get id from class selector

$('.clsName').click(function() {
    alert( this.id );
});

I have tested it properly.

Community
  • 1
  • 1
captainsac
  • 2,484
  • 3
  • 27
  • 48
3

You can use:

 $(this).attr('id');

using javascript

 this.id;

Full code:

$(".clsName").keyup(function () {
   $(this).attr('id');
});

Update:

You are having the dom:

<div class="clsName">
 <input type="number" name="first" id="first">
 <input type="number" name="second" id="second">
 <input type="number" name="third" id="third"> 

That means you have used wrong selector to target input. it should be:

$(".clsName input").keyup(function () {
  console.log($(this).attr('id'));
});

Demo

Milind Anantwar
  • 81,290
  • 25
  • 94
  • 125
2

Use this.id in pure javascript and use input event handler

    $(".clsName input").on("input",function () {
    console.log(this.id);
   });

DEMO

It's not quite an alias for keyup because keyup will fire even if the key does nothing (for example: pressing and then releasing the Control key will trigger a keyup event).

A good way to think about it is like this: it's an event that triggers whenever the input changes. This includes -- but is not limited to -- pressing keys which modify the input (so, for example, Ctrl by itself will not trigger the event, but Ctrl-V to paste some text will), selecting an auto-completion option, Linux-style middle-click paste, drag-and-drop, and lots of other things.

more detail

Community
  • 1
  • 1
Balachandran
  • 9,567
  • 1
  • 16
  • 26
1

Use .attr() in jquery.

$(".clsName").keyup(function () {
     $(this).attr('id');
});
Sudharsan S
  • 15,336
  • 3
  • 31
  • 49
0
$(".clsName").keyup(function () {
var id=$(this).attr('id');
});
RGS
  • 5,131
  • 6
  • 37
  • 65
0

as you have written "how to find which id i have clicked". so to get the click id , you should use click event not keyup

$(".clsName").on('click',function () {
   var getclickedID=$(this).attr('id');
});
Amit Kumar
  • 5,888
  • 11
  • 47
  • 85