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

  • Home
  • SEARCH
  • 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 8876193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:09:09+00:00 2026-06-14T19:09:09+00:00

I wrote jquery function for emphasis clicked <h4> tag. but it only works an

  • 0

I wrote jquery function for emphasis clicked <h4> tag. but it only works an one time. so how I solve that problem. this is my code.

   $(document).ready(function(){
        $('h4').click(function(){
            var a = $('h4').attr('style');
            if(a=='font-size: 1.5em'){
                $(this).css('font-size','2.5em');
            }
            else{
                $(this).css('font-size','1.5em');
            }
        });
    });  
  • 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-14T19:09:11+00:00Added an answer on June 14, 2026 at 7:09 pm

    If you throw a simple console.log(a) into the mix you’ll see the problem. When you do this:

    $(this).css('font-size', '1.5em');
    

    you end up setting the style attribute to font-size: 1.5em;, take note of the semicolon. So your equality test fails once you’ve toggled back to 1.5em. I wouldn’t depend on any particular format in the style attribute, there might be different numbers of spaces (possibly none) than you’re expecting, there could be semicolons where you don’t expect them, …

    You’re better off doing this using a CSS class. The HTML would look like this:

    ​<h4>Header</h4>​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​
    

    and the CSS something like this:

    ​h4 {
        font-size: 1.5em;
    }
    h4.emphasized {
        font-size: 2.5em;
    }​
    

    and finally, your JavaScript would be something nice a simple like this:

    $('h4').click(function() {
        $(this).toggleClass('emphasized');
    });
    

    Demo: http://jsfiddle.net/ambiguous/2rpxa/

    ​

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

Sidebar

Related Questions

i wrote a custom jquery function that accept a callback but not being able
I wrote this jquery which toggles each block. But when you toggle one the
is this function that i wrote in jquery, will be a good way to
So I wrote the code below: jQuery('#contentWrapper').delegate(.addButton, click, function(){ addRow(jQuery(this)); }); function addRow(thisButton){ var
$(function(){ $('a').each(function(){ var x=this.href; this.href=www.somesitename.com/filter+this.href; }); }); i wrote the above jQuery script to
i wrote this function to toggle a class name, of next div using jquery
I wrote a jQuery character counter, it works when I type, but not when
I wrote this jQuery code, but when i tried to stop the animated elements
I wrote a jQuery function that dynamically adds or removes messages boxes from the
I wrote a jQuery function that currently runs on Click Event. I need 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.