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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:22:43+00:00 2026-05-26T10:22:43+00:00

I have an array that contains values from a cookie, if one of those

  • 0

I have an array that contains values from a cookie, if one of those values matches the id of an h2 I want to add the class testing. This is the latest route I have attempted. Thanks

jQuery.each(arr, function(index, value) {
    $("h2.#" + value).addClass("testing");
});

Full code:

<script type="text/javascript">
$(document).ready(function(){
    var cookieName = $("body").attr("id");
    storedCookieName = $.cookie(cookieName);

    if (storedCookieName != null) {

        var cookieValues = storedCookieName;
        var arr = storedCookieName.split(',');
        alert( "the cookie values for this page are :" + arr);

        jQuery.each(arr, function(index, value) {
            $("#" + value).addClass("testing");
        });


    } else {
        var cookieValues = '';
        alert("I don't have a cookie for this page");
};

  //add id's to each drop down box trigger
$('h2.contentTrigger').attr('id', function(i, value) {
    return "dropDownTrigger" + (i+1);
});

//Hide (Collapse) the toggle containers on load
$(".toggle_content_container").hide(); 

//Switch the "Open" and "Close" state per click then slide up/down (depending on open/close state)
$("h2.contentTrigger").click(function(){
    $(this).toggleClass("active").next().slideToggle("fast");
    return false; //Prevent the browser jump to the link anchor
});


$("h2.contentTrigger").click(function(){

      //get class of clicked item to check if dropdown is active when clicked
    var triggerClass = $(this).attr("class");
      //get id of clicked dropdown
    var targetLink = $(this).attr("id");

    if ((triggerClass == 'contentTrigger noprint active') || (triggerClass == 'contentTrigger print active')) {
        cookieValues+=($(this).attr("id")+",");
        $.cookie(cookieName, cookieValues, { path: '/', expires: 10 });
        //alert("adding value" + cookieValues);    
    }else{
        cookieValues = cookieValues.replace(targetLink+",", "");
        $.cookie(cookieName, cookieValues, { path: '/', expires: 10 });    
        //alert("new value" + cookieValues);    
    };
});

});//end:$(document).ready
</script>

</head>
<body id="<CFOUTPUT>#SMPPageVariables.PageMetaKeywords#</CFOUTPUT>">
<div id="container">
<CFINCLUDE TEMPLATE="../libraryelements/AR_TwoDeepLeft_Navigation.element">
<div id="content">
<CFMODULE TEMPLATE="../../modules/mod_page_item_area_display.cfm" AreaID="108" PageID="#SMPPageVariables.PageID#">
<CFMODULE TEMPLATE="../../modules/mod_page_item_area_display.cfm" AreaID="109" PageID="#SMPPageVariables.PageID#">
<!--Sample of output    
<div class="tab">
    <h2 class="contentTrigger noprint"><a>What Is Important To Know</a></h2>
    <div class="toggle_content_container noprint">
        <div class="block">
            <h4>Info</h4>
            <p>Info:</p>
            <ul>
                <li>Words</li>
                <li>Words</li>
            </ul>
            <h4>Heading</h4>
            <p>Paragraph</p>
            <p>Paragraph</p>
        </div>
    </div>
</div>
-->    
</div>
<div class="hidden"><CFMODULE TEMPLATE="../../modules/mod_page_item_area_display.cfm" AreaID="110" PageID="#SMPPageVariables.PageID#"></div>
</div>
</body>
</html>
  • 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-26T10:22:44+00:00Added an answer on May 26, 2026 at 10:22 am

    You have an incorrect . in there and the h2 won’t be needed when using ids. You want this:

    jQuery.each(arr, function(index, value) {
        $("#" + value).addClass("testing");
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class that contains an array. I want this array to be
I have an array result that contains values from 0-255. I originally declared it
I have a C array fftArray[64] that contains values that I want averaged and
I have an array that contains the RGB colour values for each pixel in
Lets say I have an array numbers that contains the following values: int numbers
I have a class that contains a dynamically allocated array, say class A {
I have a vector-like class that contains an array of objects of type T
I have an array ( nodes[][] ) that contains values of effective distances that
I have an array that contains some UTF-8 characters from different languages. Every entry
I have a file that contains about 200,000 long values that I want to

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.