How to use div id and li together
I have created a dropdown by dom element and I want to do on click id value will appear in alert.
I have tried this
- $(document).ready(function() {
- $('#dropList').click(function(){
- $('li').click(function(){
- var getmyId=$(this).attr('id');
- alert (getmyId);
- });
- });
- });
By this I am getting correct value but I have to click twice and alert appearing twice and thrice.
I have also tried this
- $(document).ready(function() {
- $('#dropList li').click(function(){
- var getmyId=$(this).attr('id');
- alert (getmyId);
- });
- });
But it's not working so what should I do now?