Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7527425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:06:06+00:00 2026-05-30T04:06:06+00:00

lets say I wanted to search through divs with a certain class name.and if

  • 0

lets say I wanted to search through divs with a certain class name.and if the divs dont have a certain id I want to add a class to them. ex.

<div id ="1" class="head"></div>
<div id ="2" class="head"></div>
<div id ="3" class="head"></div>

  if(div.id != "1")
 {
  add class to all divs not = 1
 }

how would this work thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T04:06:08+00:00Added an answer on May 30, 2026 at 4:06 am

    jQuery

    You can use this code to do that…

    $('div.head:not(#1)').addClass('some-class');
    

    jsFiddle.

    For better performance, use…

    $('div.head').not('#1').addClass('some-class');
    

    jsFiddle.


    Without jQuery

    For modern browsers…

    [].slice.call(document.querySelectorAll('div.head')).filter(function(element) {
        return element.id != 1;
    }).forEach(function(element) {
        element.classList.add('some-class');
    });
    

    jsFiddle.

    You could drop the filter() and use :not(), like Zeta’s answer.

    For our lovable older IEs…

    var divs = document.getElementsByTagName('div'),
        divsLength = divs.length;
    
    for (var i = 0; i < divsLength; i++) {
        if (divs[i].id != '1' && ~divs[i].className.search(/\bhead\b/)) {
            divs[i].className += ' some-class';    
        }
    }
    

    jsFiddle.

    Depending on how far you need to support, you could always use document.getElementsByClassName() so long as you know you will be required to filter div elements if other elements may contain the same class name and you must have div exclusively.


    Additionally, an id attribute can not start with a number, according to the spec.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say i wanted to add another variable to the database can anybody tell
Currently, I am doing a search function. Lets say in my database, I have
lets say i have a tree of the following structure: <div>node level1 <div>node level2
Lets say I have the following data: <XmlDataProvider x:Key=Values> <x:XData> <folder name=C:> <folder name=stuff
is there an easy way to go through a list? lets say i wanted
Lets say that in this case i have 4 divs called .CountThese and i
Let's say you wanted to implement a breadth-first search of a binary tree recursively
Lets say I wanted to scrape a webpage, and extract some data. I'd most
Lets say i wanted to compare a variable in the sqlite database and if
As an example, lets say I wanted to list the frequency of each letter

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.