<div class="field_wrapper_1">
<span class="error php-error" id="php-error_includes" style="display: none"></span>
<div class="row">
<div class="col-md-11">
<div class="form_group">
<label class="form_label">Includes <span>*</span></label>
<input class="form_input" name="includes[][]" id="includes" placeholder="Enter the details of fees includes" type="text">
</div>
</div>
<div style="padding-top: 3.6%;" class="col-md-1">
<a href="javascript:void(0);" class="add_button" onclick="addIncludeTextBox(this)" title="Add field"><i class="fa fa-plus" aria-hidden="true"></i></a>
</div>
</div>
</div>
在单击函数“ addIncludeTextBox”时如何获取该类名
答案 0 :(得分:1)
您可以这样做:
$(obj).closest('[class^=field_wrapper]').attr("class")
合并.closest
和.attr
来获得课程。
可选,您也可以只使用.closest('.field_wrapper_1')
工作演示
function addIncludeTextBox(obj){
console.log($(obj).closest('[class^=field_wrapper]').attr("class"))
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="field_wrapper_1">
<span class="error php-error" id="php-error_includes" style="display: none"></span>
<div class="row">
<div class="col-md-11">
<div class="form_group">
<label class="form_label">Includes <span>*</span></label>
<input class="form_input" name="includes[][]" id="includes" placeholder="Enter the details of fees includes" type="text">
</div>
</div>
<div style="padding-top: 3.6%;" class="col-md-1">
<a href="javascript:void(0);" class="add_button" onclick="addIncludeTextBox(this)" title="Add field"><i class="fa fa-plus" aria-hidden="true">+</i></a>
</div>
</div>
</div>