Jquery - 条件包含最近的元素
Jquery - conditional contain of the closest elem
我试图在单击“删除元素”时刷新页面,但前提是最接近的“产品标题”包含特定文本。下面的 jquery 代码不起作用。
如果你有什么想法,谢谢。
$( document ).ready(function(){
$(".delete-item").on( "click", function( reloadEvent ) {
if( $( reloadEvent.target ).closest(".Product-details").find(".Product-title:contains('XYZ')").lenght)
{location.reload.bind(location);}
else {}
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="Product-details">
<div class="Product-header">
<span class="Product-title">Product title A</span>
<div/>
<div class="Product-footer">
<div class="delete-action">
<a href="#" class="delete-item">DELETE</a>`
</div>
</div>
</div>
<div class="Product-details">
<div class="Product-header">
<span class="Product-title">Product title B</span>
<div/>
<div class="Product-footer">
<div class="delete-action">
<a href="#" class="delete-item">DELETE</a>`
</div>
</div>
</div>
我会这样写:
$(".delete-item").on( "click", function( ) {
if( $( this ).closest(".Product-details").find(".Product-title:contains('XYZ')").length)
{location.reload.bind(location);}
else {}
})
我试图在单击“删除元素”时刷新页面,但前提是最接近的“产品标题”包含特定文本。下面的 jquery 代码不起作用。 如果你有什么想法,谢谢。
$( document ).ready(function(){
$(".delete-item").on( "click", function( reloadEvent ) {
if( $( reloadEvent.target ).closest(".Product-details").find(".Product-title:contains('XYZ')").lenght)
{location.reload.bind(location);}
else {}
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="Product-details">
<div class="Product-header">
<span class="Product-title">Product title A</span>
<div/>
<div class="Product-footer">
<div class="delete-action">
<a href="#" class="delete-item">DELETE</a>`
</div>
</div>
</div>
<div class="Product-details">
<div class="Product-header">
<span class="Product-title">Product title B</span>
<div/>
<div class="Product-footer">
<div class="delete-action">
<a href="#" class="delete-item">DELETE</a>`
</div>
</div>
</div>
我会这样写:
$(".delete-item").on( "click", function( ) {
if( $( this ).closest(".Product-details").find(".Product-title:contains('XYZ')").length)
{location.reload.bind(location);}
else {}
})