0

Is is possible to do something like this in Jquery?

$("a[data-tooltip-content*!='Public')")    - not containing any substring of "Public"

intended code:

$("a[data-tooltip-content!*='Public'][data-tooltip-content!*='Only Me'][data-tooltip-content!*='friends']").closest(".userContentWrapper._5pcr,._2tdc").css({"background-color": "violet"});
$("a[data-tooltip-content*='Public']").closest(".userContentWrapper._5pcr,._2tdc").css({"background-color": "yellow"});
$("a[data-tooltip-content*='Only Me']").closest(".userContentWrapper._5pcr,._2tdc").css({"background-color": "lime"});
$("a[data-tooltip-content*='friends']").closest(".userContentWrapper._5pcr,._2tdc").css({"background-color": "cyan"});

1st line: if ("Public","Only Me","friends") are not found, set colour to "Violet"

7
  • Have you tried? And, if you do, make sure the selector you write is valid (the one you've shown isn't); Commented Dec 2, 2016 at 15:32
  • there's nothing wrong with it?? i have tried it but it's not working!! Commented Dec 2, 2016 at 15:34
  • i have just tried to recode it again, this selector is definitely valid because i am able to invoke css background colour to 'Facebook Statuses' except the first line of code (violet), and i have tried console.log between the first line of code, and it appears that the programme will stopped running after i runs the differentmultiple attribute selector Commented Dec 2, 2016 at 15:42
  • The selector is definitely NOT valid. There is something wrong with it... You are missing the closing square bracket. Commented Dec 2, 2016 at 15:42
  • And the closing quote mark. Although I'm amazed that works at all, given the !*= syntax. Commented Dec 2, 2016 at 15:43

3 Answers 3

2

Your problem is probably not with multiple attribute selectors, but with the not selector (which doesn't exists).

You can't use the ! for "not contains", however you can use the :not([class*="Public"]).

Here is a working example (is just a css example, but works exactly the same with jQuery's css selectors:

div {
  background: red;
}
div:not([class*="asd"]) {
  background: green;
}
<div class="asd">123</div>
<div class="dsa">456</div>
<div class="">789</div>

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

1 Comment

thanks for the help!!! :) can i get an opinion in changing the title of this post to a better title to prevent misleading of question?
2

You can make use of jQuery's :not()-Selector

$("a:not([data*='Public'])");

Comments

1

Yes, using :not()

$('a:not([data-tooltip-content*="public"])')

Select all <a> tags that do not contain a data attribute that contains post

$('a:not([data-tooltip-content*="public"])').css('background-color', '#f00')
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a href="#" data-tooltip-content="public">a link</a>
<a href="#" data-tooltip-content="private">another link</a>
<a href="#" data-tooltip-content="help me">aaaaanother link</a>
<a href="#" data-tooltip-content="public thingy">abbbnother link</a>

Comments

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.