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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:01:59+00:00 2026-05-11T20:01:59+00:00

What im trying to do is when the p inherits the class active that

  • 0

What im trying to do is when the p inherits the class “active” that div.test will print the link rel correctly.

Currently if the page loads without the class assigned to the p tag, it will not. How can I make it happen when the p tag inherits the class “active” the link printed in div.test will get the rel printed correctly?

$(document).ready(function(){
    var relvar = $('p.active').attr('rel');
    $("div.test").html("<a rel='"+ relvar +"'>hello</a>");

    $("p").click(function () {
    $(this).toggleClass("active");
    });

    });
  • 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-11T20:01:59+00:00Added an answer on May 11, 2026 at 8:01 pm

    I am not sure what you asking. Are you saying that you would like this code:

    var relvar = $('p.active').attr('rel');
    $("div.test").html("<a rel='"+ relvar +"'>hello</a>");
    

    To be run whenever the <p> element changes classes? If so, there is no “onchangeclass” event or anything like that, but you could actually create your own event to handle this:

    $('p').bind('toggleActive', function() {
        if($(this).hasClass('active')) {
            var relvar = $(this).attr('rel');
            $("div.test").html("<a rel='"+ relvar +"'>hello</a>");        
        }
    }).click(function() {
        $(this).toggleClass('active').trigger('toggleActive');
    });
    

    Check this code in action.

    This is actually kind of roundabout – it would be simplest to just do the logic in the click handler itself. The main advantage of moving it to its own event is that if you then need to do this elsewhere in the code you can keep that logic separate and just “trigger” it as you need.

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

Sidebar

Related Questions

I'm trying to create a custom javascript class that inherits from google.maps.Map (V3 API).
I'm trying to create a class that inherits from ListViewItemCollection, and I got this
I'm trying to serialize a class that inherits from a base class that implements
I am trying to create a custom dialog class that inherits from Dialog that
I'm trying to build a class that inherits methods from Python's list, but also
I am trying to create a custom object that simply inherits the NSString class
I'm trying to create a UserControl that inherits from a generic class. It does
I have a class that inherits from UIView However when trying to use the
I have a class that inherits from an abstract base class. I am trying
I'm trying to get the absolute pathname of a PHP class that inherits from

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.