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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:00:29+00:00 2026-05-19T12:00:29+00:00

I have a link like this : <a href=# onclick=renkDegistir() title=Yaz ……. And JS

  • 0

I have a link like this :

<a href="#" onclick="renkDegistir()" title="Yaz .......

And JS code :

function renkDegistir()
    {  
        $("#cont #main article").addClass("siyah-stil");
    }

When click this link siyah-stil class is added to article. But i want to do, if link clicked 2nd time remove siyah-stil class.

In summary ,

on first click : addClass("siyah-stil");
on second click : removeClass("siyah-stil");
  • 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-19T12:00:30+00:00Added an answer on May 19, 2026 at 12:00 pm

    Try using toggleClass():

    function renkDegistir()
    {
        $("#cont #main article").toggleClass("siyah-stil");
    }
    

    But I’d suggest also removing the in-line onclick attribute, and switching to jQuery’s click() event-handler:

    $('a').click(
        function(){
            $("#cont #main article").toggleClass("siyah-stil");
        });
    

    Edited to address @Eray’s comment (below):

    Can you explain [to] me , why jQuery’s click() function [is] better than in-line onclick attribute?

    The reason I prefer to use non-inline code is that it reduces the complexity of changing the onClick events; since they get changed in one place, rather than having to change the onclick attribute in every a (or other) element. Admittedly, you could achieve that benefit by simply changing the renkDegistir() function, but then you end up with functions named for posterity, rather than the inherent nature of the function.

    It also makes it easier for others to take over, and adapt your code, and to iron out bugs when they appear.

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

Sidebar

Related Questions

I have a link that looks like this: <a onclick=myLightbox rel=lightbox href=image.jpg title=> I
i have a html like this <a href=link.php onClick=return false;>Click me</a> $('a').click(function() { var
I have an html page with a link like this: <a href=javascript:window.print()>Print QR code</a>
I have a link like this: <a href=/index2.php?option=com_jumi&amp;fileid=3&amp;Itemid=11 onclick=window.open(this.href,'targetWindow','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,') I want the new opening
So I have something like this situation: $(document).on('click', 'a[data-link]', function () { var $this
I have a html like this: <html> <head> <link rel=stylesheet type=text/css media=all href=style.css> </head>
I have a horizontal menu on a page like this <link rel=stylesheet type=text/css href=/classified/siteassets/css/mymenu.css
As you all know, it's extremely common to have code like this: <a href='#'
Hay i have a link like this index.php?sometext=f,fsdsd,rerw,e,wewewe and when i use .attr(href) on
I have a link as follows: <a onclick=runSomeJsonpCall(); href=www.goherenext.com> make this work </a> The

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.