byCoder
byCoder

Reputation: 9184

Jquery set quotes in quote

I have such code:

$("input[id="+id.slice(0,-1)+"-br-"+brand+"].qnt_to_cart").show();

which generate me:

input[id=02620-br-FEBI BILSTEIN].qnt_to_cart 

But i need to see something like:

input[id="02620-br-FEBI BILSTEIN"].qnt_to_cart 

So what i need to write? How to set quote in quote?

upd

why i still see:

Uncaught Error: Syntax error, unrecognized expression: input[id=02620-br-FEBI BILSTEIN].to-cart 

Upvotes: -1

Views: 118

Answers (3)

Nevir
Nevir

Reputation: 8101

You've got a couple options in JavaScript, you can contain them in ' instead of ":

$('input[id="'+id.slice(0,-1)+'-br-'+brand+'"].qnt_to_cart').show();

or you can escape the quotes via \":

$("input[id=\""+id.slice(0,-1)+"-br-"+brand+"\"].qnt_to_cart").show();

Upvotes: 1

pktangyue
pktangyue

Reputation: 8544

$('input[id="'+id.slice(0,-1)+'-br-'+brand+'"].qnt_to_cart').show();

Upvotes: 2

dimusic
dimusic

Reputation: 4133

use \" to escape quotes:

$("input[id=\""+id.slice(0,-1)+"-br-"+brand+"\"].qnt_to_cart").show();

Upvotes: 6

Related Questions