[英]Remove li with attribute jQuery
I need to remove a list item li that has a specific attribute. 我需要删除具有特定属性的列表项li。
My current attempts fail. 我目前的尝试失败了。
id = $(this).attr('data-id');
$.post('uri.../delete_file/' + id).done(function(data)
{
var obj = jQuery.parseJSON(data);
if (obj.status == 'success')
{
$('li["data-id=' + id +'"]').remove();
}
}
FireBug is informing that the jQuery expression is wrong. FireBug告知jQuery表达式是错误的。
$('li["data-id=' + id +'"]').remove();
The list item must have an attribute of data-id=""
列表项必须具有
data-id=""
的属性
UPDATE - PHP and HTML 更新 - PHP和HTML
<?php foreach($files as $file): ?>
<li data-id="<?php echo $file->id;?>">
<a href='#' class='delete_file' data-id="<?php echo $file->id;?>">[X] Delete</a>
</li>
<?php endforeach;?>
UPDATE 2 - Message from FireBug 更新2 - 来自FireBug的消息
Error: Syntax error, unrecognized expression: ["data-id=1"]
throw new Error( "Syntax error, unrecognized expression: " + msg );
I think you wrong on putting double quote. 我认为你把双引号弄错了。 it's must:
它必须:
$('li[data-id="' + id +'"]').remove();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.