Get Parent ID of this DIV

前端 未结 7 1185
野性不改
野性不改 2021-01-21 09:45

I am looking to find the parent div id (i.e. \"Bakerloo\") from this layout when the button is clicked within \".buttonleft0\" in jquery / javascript.

相关标签:
7条回答
  • 2021-01-21 10:46

    Your code itself have few errors so here is the correct one:

    HTML

    <div id='Bakerloo' class='box'>bakerloo<p></p><span class='buttons'>
    <span class='buttonleft0'><button><span class='icon icon10'>Click here</span>
    </button>
    </span><span class='buttonleft'></span><span class='buttonright'></span></span>
    <div class='comingup'></div>
    <div class='more'></div></div>
    

    JQuery

    jQuery(document).ready(function($){
        $("button").on('click',function(){
           alert($(this).closest('div').attr('id'));
        });
    });
    

    here is the fiddle http://jsfiddle.net/cpeeyush/ydk4e/

    0 讨论(0)
提交回复
热议问题