raygo
raygo

Reputation: 1398

Multiple selectors: unrecognized expression

I need to select a hidden field in order to remove it. I want to select it by type, a custom data attribute and by name. My selector looks like:

$("input[type=hidden] data-supplied='Cola' name='companies[\"4425506\"]'").remove();

This is giving me the error:

Uncaught Error: Syntax error, unrecognized expression: input[type=hidden data-supplied='Cola' name='companies["4425506"]'] 

Any idea of whats wrong? Thanks.

Upvotes: 0

Views: 871

Answers (2)

Salman Arshad
Salman Arshad

Reputation: 272246

You are trying to match multiple attributes. This works just like matching one attribute; just add as many [name=value] selectors as you like, not separated by anything:

   input[type=hidden][data-supplied='Cola'][name='companies[\"4425506\"]']

Your code becomes:

$("input[type=hidden][data-supplied='Cola'][name='companies[\"4425506\"]']")

Upvotes: 2

meadowstream
meadowstream

Reputation: 4141

This is how you select multiple attributes. (See jquery docs)

 $("input[type=hidden][data-supplied='Cola'][name='companies[\"4425506\"]']");

However, I would recommend adding a class to your html:

<input[type=hidden] data-supplied='Cola' name='companies[\"4425506\"]' class="tada" />

Then enjoy readable javascript:

$("tada").remove();

Upvotes: 0

Related Questions