2

I'm trying to use jquery show and hide methods with html5 attributes.

Here is what i'm trying to do:

html file :

<div class="test" data-location="paris">Math</div>
<div class="test" data-location="paris">Physics</div>
<div class="test" data-location="paris">Chemistry</div>
<div class="test" data-location="paris">Biology</div>

script:

$("[data-location="paris"]").hide(); 

I'm using the jquery to hide all the divs with data-location="paris". I don't know why i can't do it. Help?

4
  • 1
    try to remove additional quotes $("[data-location=paris]").hide(); Commented Dec 22, 2014 at 2:36
  • 2
    If you're going to add quotes before and after paris, make sure to escape them.$("[data-location=\"paris\"]").hide(); Commented Dec 22, 2014 at 2:37
  • @vladkras that doesn't work too. Commented Dec 22, 2014 at 2:41
  • 1
    @AnudeepKatragadda nope, it works: proof. Maybe you have some errors before, check your console Commented Dec 22, 2014 at 2:46

2 Answers 2

2

Use this.

$("[data-location='paris']").hide();

JsFiddle : http://jsfiddle.net/getmanzooronline/3rcd1wnc/1/

Sign up to request clarification or add additional context in comments.

Comments

0

Simply use single quotes instead of double. This will work: $("[data-location='paris']").hide();

Or escape your double quotes, like this:

$("[data-location=\"paris\"]").hide();

You were ending your code statement early. $("[data-location=" was all that was being run. Big error there!

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.