Skip to content
Advertisement

Jquery Syntax error, unrecognized expression on attribute selector

I have html div with one attribute.

div exp_attribute="{"prop_val_name":1}">mydiv</div>

I tried to trigger click on it via jQuery like

$('div[exp_attribute={"prop_val_name":1}]').click();   // not working
$('div[exp_attribute=\{"prop_val_name":1\}]').click();   // not working with escaping special chars
$('div[exp_attribute=\{\"prop_val_name\":1\}]').click();   // not working with escaping more special chars

but keep getting error

Error: Syntax error, unrecognized expression: div[exp_attribute={"prop_val_name":1}]

so any idea how to handle the issue?

Advertisement

Answer

Better to escape everything

$('div[exp_attribute=\{\"prop_val_name\"\:1\}]').click();
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement