1

As far as I know, I'm following the correct usage form on: http://api.jquery.com/multiple-attribute-selector/, but for whatever reason I'm not seeing, my code is not working. Each attribute works fine independently of one another (i.e. $(".tonight_stat_peopleThumbs li[srcid="+srcid+"]") works and $(".tonight_stat_peopleThumbs li[style*=inline-block]") works) but they do not work together.

Here is my function in the JavaScript:

hidePatrons = function(srcid) {
    $(".tonight_stat_peopleThumbs li[srcid="+srcid+"][style*=inline-block]").each(function(){
        $(this).css({"display" : "none"});
    });
}

Here is a piece from the HTML:

<ul activepage="1" class="tonight_stat_peopleThumbs" style="width:171px">
  <li id="myid" class="myclass" ptype="people" ptime="11101101" style="display:inline-block;">
    <a href="http://domain.com/users/#.php">
      <img src="https://graph.facebook.com/#/picture" />
    </a>
  </li>
</ul>

NOTE: The '#' are inserted for privacy, assume they are fbid numbers.

4 Answers 4

5

Note that while CSS allows attribute selectors without quotes, there are quotes in every jQuery example. My experience has been that jQuery does not select reliably without quotes.

/* Good for CSS, bad for jQuery */
[foo=bar]

/* Good for both */
[foo="bar"]
Sign up to request clarification or add additional context in comments.

Comments

1

Try

$('.tonight_stat_peopleThumbs li[srcid="' + srcid + '"][style*="inline-block"]')
  • mind the quoting!

Comments

0

try changing li[srcid="+srcid+"] to li[id="+srcid+"] I don't see a "srcid" attribute so I assume you are looking to search on the "id" attribute

Comments

0

can you please try like this way? the following is working fine for me for your HTML code.

 hidePatrons = function(srcid) {
        $("#tonight_stat_peopleThumbs li[ptype=people][style*=inline-block]").each(function(){
            $(this).css({"display" : "none"});
        });
    }

note: # is for id, and . is for class. I changed . to # and srcid="+srcid+" to ptype=people from your code.

1 Comment

That was a typo on my part; I have a sandbox and a live, put the wrong one on here, changed it in my above though, thanks for the catch! :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.