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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:03:40+00:00 2026-06-09T07:03:40+00:00

I want to convert this functionality from mouseover and mouseout to click event below

  • 0

I want to convert this functionality from mouseover and mouseout to click event below is the code.

var IdAry=['slide2','slide3','slide4','slide5','slide8','slide9','slide12','slide13','slide14','slide15','slide16'];
window.onload=function() {
 for (var zxc0=0;zxc0<IdAry.length;zxc0++){
  var el=document.getElementById(IdAry[zxc0]);
  if (el){
   el.onmouseover=function() {
     changeText(this,'hide','show')
    }
   el.onmouseout=function() {
     changeText(this,'show','hide');
    }
  }
 }
}
function changeText(obj,cl1,cl2) {
   obj.getElementsByTagName('SPAN')[0].className=cl1;
   obj.getElementsByTagName('SPAN')[1].className=cl2;
}

and below is the HTML part

<div id="graphics">
                    <img src="images/circle-bg.jpg" alt="" class="circleBg"/>
                    <div class="row1">
                        <a href="#" id="slide1" id="selectedSlide">
                            <span id="span1"></span>
                            <span class="hide"></span>
                        </a>
                        <a href="#" id="slide2">
                            <span id="span1"></span>
                            <span class="hide">At this stage, we sit down together and discuss your life goals and begin to develop a plan for funding them. Without knowing where you want to go, we can't help get you there! This is the time to ask a lot of questions and get to know each other. </span>                      
                        </a>
                        <a href="#" id="slide3">
                            <span id="span1"></span>
                            <span class="hide">We need to know your current income and expenses in order to gain a better understanding of resources that can be applied toward your financial goals. We also determine the appropriate size of your emergency fund. </span>
                        </a>
                        <a href="#" id="slide4">
                            <span id="span1"></span>
                            <span class="hide"></span>                      
                        </a>
                    </div>
                </div>

Currently when user mouseover anchor tag of id slide1, slide2, slide3.. etc it added class show to one span and hide to other and vice versa in mouseout.

So if is possible to convert this functionality to click event instead of mouseover and mouseout.

Thanks in Advance

  • 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-09T07:03:43+00:00Added an answer on June 9, 2026 at 7:03 am

    I assume you want to toggle with each click.

    Here I do the handler assignment in a separate function, so that each handler can have access to its own local variables.

    Then I put the "show" and "hide" in an Array within that function, and on each click the Array is reversed, and passed to changeText using .apply to invoke it.

    var IdAry = ['slide2', 'slide3', 'slide4', 'slide5', 'slide8', 'slide9', 'slide12', 'slide13', 'slide14', 'slide15', 'slide16'];
    window.onload = function () {
        for (var zxc0 = 0; zxc0 < IdAry.length; zxc0++) {
            var el = document.getElementById(IdAry[zxc0]);
            if (el) {
                setUpHandler(el);
            }
        }
    }
    
    function setUpHandler(el) {
        var state = ["show", "hide"];
    
        el.onclick = function () {
            changeText.apply(this, this, state.reverse());
        }
        el = null;
    }
    
    function changeText(obj, cl1, cl2) {
        obj.getElementsByTagName('SPAN')[0].className = cl1;
        obj.getElementsByTagName('SPAN')[1].className = cl2;
    }
    

    If you don’t like the idea of reversing a short Array each click, then you could do this instead…

    function setUpHandler(el) {
        var ab = true;
    
        el.onclick = function () {
            ab = !ab
            changeText(this, 
                       ab ? "show" : "hide", 
                       ab ? "hide" : "show");
        }
        el = null;
    }
    
    function changeText(obj, cl1, cl2) {
        obj.getElementsByTagName('SPAN')[0].className = cl1;
        obj.getElementsByTagName('SPAN')[1].className = cl2;
    }
    

    Or since you tagged jQuery, you could do this…

    $("#" + IdAry.join(",#")).toggle(function() { changeText(this, "hide", "show"); }),
                                     function() { changeText(this, "show", "hide"); }));
    

    var prev;
    
    function changeText(obj, cl1, cl2) {
    
        obj.getElementsByTagName('SPAN')[0].className = cl1;
        obj.getElementsByTagName('SPAN')[1].className = cl2;
    
        if (prev && obj !== prev) {
            prev.getElementsByTagName('SPAN')[0].className = "";
            prev.getElementsByTagName('SPAN')[1].className = "";
        }
        prev = obj
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to convert vb this code <?php // Where the file is going
i want convert this c++ code in C#: RECT rcCurrent; ::GetWindowRect ( hwndChild, &rcCurrent
this jquery code works fine for me in jquery format. I want convert this
I want to convert this linear loop into a concurrent one: for(Item item :
i want to convert this array Array ( [2] => Array ( ) [4]
i want to convert this string into DateTime. Tue Aug 19 15:05:05 +0000 2008
i have an array and i want to convert this array in comma seprated
Say I have the string 1,2,3,4,5 and I want to convert this to an
I have a date in String format, mm/dd/yyyy I want to convert this to
I have tif image in 16 bit format. Now I want to convert this

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.