Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

jquery not selector

Posted on 2016-10-20
4
Medium Priority
?
84 Views
Last Modified: 2016-10-20
I have this fiddle

https://jsfiddle.net/56p5z2ob/

If you inspect the html with the google chrome inspection tool you can see this is the html rendered.

the html rendered
Notice how my fiddle adds the class="AppleStyle1" to  any span tag whose id ends in DivImageContainer_Span2

https://api.jquery.com/not-selector/

How do i add the not selector on this line:
$("span[id$='DivImageContainer_Span2']").addClass("AppleStyle1");

so basically i want to opposite of my fiddle above.

I want to add this class="AppleStyle" to  any span tag whose id doe not end in DivImageContainer_Span2

Anyone know the syntax?
0
Comment
Question by:maqskywalker
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 7

Expert Comment

by:Thomas Wheeler
ID: 41852443
I think what you want is this
 $("span[id!='DivImageContainer_Span2']").addClass("AppleStyle1");

Open in new window


This will apply the style to all divs that are not "DivImageContainer_Span2"
0
 
LVL 1

Author Comment

by:maqskywalker
ID: 41852527
Sorry my fiddle was wrong, this fiddle is correct fiddle.

https://jsfiddle.net/3p3qfyyq/

I tried your solution on this fiddle but that didn't work.
I'm looking for spans those id does NOT end or contains this string "DivImageContainer_Span2"

I think your solution is doing does not equal to a specific string.  I
0
 
LVL 7

Accepted Solution

by:
Thomas Wheeler earned 2000 total points
ID: 41852657
so you would want something like this
$("span").not("[id*='DivImageContainer_Span2']").addClass("AppleStyle1");

Open in new window

https://jsfiddle.net/3p3qfyyq/1/
0
 
LVL 1

Author Closing Comment

by:maqskywalker
ID: 41852894
thanks
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question