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 3947706
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:17:02+00:00 2026-05-20T01:17:02+00:00

Have a body tag on a page that has both an id and a

  • 0

Have a body tag on a page that has both an id and a class:

<body class="class" id="id">

I’m trying to use jQuery to chance some content further down the page, based on what the class AND the id are. I’ve had no success, for what it’s worth, here’s what I tried to do:

if($('body').is('#id1')){
    if($(this).hasClass('class1')){
        $('ul.nav li.first').html('<h2>Special Title</h2>');
    }else if($(this).hasClass('class2')){
        $('ul.nav li.first').html('<h2>Other Title</h2>');
    }
}else if($('body').is('#id2')){
    if($(this).hasClass('class1')){
        $('ul.nav li.first').html('<h2>Special Header</h2>');
    }else if($(this).hasClass('class2')){
        $('ul.nav li.first').html('<h2>Other Title</h2>');
    }
}

Anyone have a quick way of doing this? I’m terrible at “if” looping using jQuery, always have been.

Cheers,

T

  • 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-20T01:17:03+00:00Added an answer on May 20, 2026 at 1:17 am

    For the record there is no need to use jQuery here.

    var isId = (document.body.id === someId);
    var isClass = (document.body.className.indexOf(someClass) !== -1);
    
    if (isId && isClass) {
         // do something
    }
    

    [Edit]

    The class check is horrible. Try

    var regexp = new RegExp("(^|//s)" + someClass + "($|//s)", "m");
    var isClass = (document.body.className.search(regexp) !== -1);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have a page that has the following in its body tag: In
I have a page that has a tag <body onload="setInterval('window.location.reload()', 60000);"> that causes the
I have a web page that has the following content (I've changed the URL
I have an HTML page that has varying types of content. I would like
So I have this page on one domain that has a script-tag pointing on
I have a simple single page web site that has some navigation with named
I have data-segment attribute in my body tag that is changed by a slider.
I'm writing a webmail product and some emails have body css that changes the
I have a page that has the conditional comment: <%@ Page language=c# %> <html>
I am trying to append to $('body'), but some sites use full html pages

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.