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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:48:16+00:00 2026-06-15T11:48:16+00:00

Possible Duplicate: How to get elements with multiple classes Working on a bit of

  • 0

Possible Duplicate:
How to get elements with multiple classes

Working on a bit of javascript code that sets the current URL of the referring page to pass into an iframe widget. No control over the code of the page on which the javascript resides, except for the one bit of javascript code.

An example of the element value I need to grab is as follows:

<div id="new_p_2FRolls-Royce_p_2F2013-Rolls-Royce-Phantom_p_2BDrophead_p_2BCoupe-4a5be12c0a0a00650143b598a45df25d_p_2Ehtm" class="page NEW_VEHICLE_DETAILS current">

What I’m trying to do is select the div by combining classes “page” and “current”. In this example, “NEW_VEHICLE_DETAILS” is unique to this page, and varies on other pages. I would like to create a consistent bit of code that doesn’t have to be altered for each page as it is currently. Here is the code I am using right now:

<div id="build_iframe"></div>
<script>
var pageid = document.getElementsByClassName('NEW_VEHICLE_DETAILS')[0].id;
var currenturl = 'http://m.whateverwebsite.com/index.htm#'+pageid;
var shareurl = escape(currenturl);
document.getElementById('build_iframe').innerHTML = '<iframe style="border:1px;width:100%;height:110px;" src="http://widget.mywidgetwebsite.com/share-tool/?current_url='+shareurl+'"></iframe>';
</script>

jQuery is not an option in this case. How can I get the value of the ID by selecting only the element with BOTH “page” and “current” classes set?

  • 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-06-15T11:48:18+00:00Added an answer on June 15, 2026 at 11:48 am

    You could use querySelector (or querySelectorAll if there’s more than one matching element and you want to get a reference to all of them):

    var elem = document.querySelector(".page.current");
    

    You can also actually just use getElementsByClassName, which accepts a space-separated list of class names:

    var elems = document.getElementsByClassName("page current");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Get URL of ASP.Net Page in code-behind I'm trying to hold current
Possible Duplicate: Get number of checkboxes that are checked in Javascript obj = document.getElementById('myform').elements.length.checked;
Possible Duplicate: How to get a list of all elements that resides at the
Possible Duplicate: Get variable name. javascript “reflection” Is there a way to know the
Possible Duplicate: Get image data in Javascript? Convert an image into binary data in
Possible Duplicate: get name of current PHP script in include file Can an included
Possible Duplicate: How can I match multiple occurrences with a regex in JavaScript similar
Possible Duplicate: JavaScript: How do I print multiple script tags in a loop? Im
Possible Duplicate: Get list of all input objects using JavaScript, without accessing a form
Possible Duplicate: Children of XElement I want to get child elements from XElement using

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.