我需要使用div名称来获取div id及其子类名。但div Id将始终不同且独特。
HTML
<div class="diagram" id="12" >
<div class="121">
...
</div>
</div>
<div class="diagram" id="133" >
<div class="33">
...
</div>
</div>
<div class="diagram" id="199" >
<div class="77">
...
</div>
</div> So on..
JQUERY
$(function(){
//i need to pass to values to the function in the following way
o.circle("12","121");
o.circle("133","33");
o.circle("199","77");
//So on..
});
请帮帮我
答案 0 :(得分:3)
$('div.diagram').each(function() {
// this.id -> get the id of parent i.e div.diagram
// $('div:first', this) -> get the first child of diagram, here this refers to diagram
// $('div:first', this).attr('class') -> get the class name of child div
o.circle(this.id, $('div:first', this).attr('class'));
});
如果您想对任何事件进行尝试,请尝试:
示例:
// I assumed a click event
$('div.diagram').on('click', function() {
o.circle(this.id, $('div:first', this).attr('class'));
});
答案 1 :(得分:0)
你可以使用它。它对我来说很好。
$('div.diagram').on('event_name', function() { // use click, hover, change, focus at the place of event_name whatever you need
o.circle(this.id, $('div:first', this).attr('class'));
});