Reputation: 2686
This is my piece of code :
.................
remProduct: function(e, $a) {
var orderObj = {
pid: $a.parents('li').find('input=[name=pid]').val(),
pk_id: $a.parents('div.packet').attr('id') || $a.parents('div.section').attr('id'),
isSideCart: !!$a.parents('div.packet').length
};
var callBack = function(json) {
if (json.success) {
if ($("div.sidebar").length) {
$("div.sidebar").replaceWith(json.body)
} else if ($("div.content").length) {
$("div.content").html(json.body);
}
}
front.rebindSideCart();
};
$.post(this.getPath() + '/remove-product', orderObj, callBack, 'json');
},
.................
The idea is that I add or remove product from my Package. When I add a product and after that I want to remove it , it doesn't work and the firebug show me this error:
Error: Syntax error, unrecognized expression: input=[name=pid]
, BUT if i refreshed the page it works. Can anyone explain me why ? Thx in advance !
Upvotes: 1
Views: 34
Reputation: 40639
It should be input[name=pid]
not input=[name=pid]
pid: $a.parents('li').find('input[name=pid]').val(),
//--------------^
// remove = from this position as it is not a valid selector
Syntax:
$("element[attribute='value']")
For egs:
$("input[name='pid']")
Upvotes: 1
Reputation: 38102
You don't need to use =
right after input
inside input=[name=pid]
:
pid: $a.parents('li').find('input[name=pid]').val(),
The correct syntax for Attribute Equals Selector is: jQuery("[attribute='value']")
.
Since your value is just a normal string then you don't need to wrap it inside double quotes, but if your value contain any of the meta-characters ( such as !"#$%&'()*+,./:;<=>?@[\]^
{|}~` ) as a literal part of a name, then it must be escaped with with two backslashes: \\ or wrapped in quotes.
Upvotes: 1
Reputation: 82231
You dont need =
operator after input
.also wrap attribute value in quotes.it should be:
find('input[name="pid"]')
pid :
pid:$a.parents('li').find('input[name="pid"]').val(),
Upvotes: 1