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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:25:23+00:00 2026-05-26T13:25:23+00:00

I ashamed and frustrated by this question. I’m writing what should be a pretty

  • 0

I ashamed and frustrated by this question. I’m writing what should be a pretty simple script that removes “y”s and replaces them with “i”s. When this happens, I add a with a class to the new “i” so that I can undo it. For some reason, the first replacement works… the switch back works… it works AGAIN… then stops. I don’t know what else to do but just post the whole ugly script.

Don’t worry about the gnarly regex expression (it’s targeting only certain “y”s which are sometimes used for writing Mohawk).

EDIT: Here’s a live version on jfiddle: http://jsfiddle.net/vkVBk/

$(document).ready(
function() {

    function swap_out_y(x) {
        //alert(x);
        x = x.replace(/y/, "i");
        x = x.replace(/Y/, "I");
        alert('swap_out_y just ran. x = '+x);
        return x;   
    }

    function swap_out_i(x) {
        //alert(x);
        x = x.replace(/i/, "y");
        x = x.replace(/I/, "Y");
        alert('swap_out_i just ran. x = '+x);
        return x;   
    }

    $('body').delegate('.y_to_i', 'click', y_to_i);
    //$('body').delegate('.i_to_y', 'click', i_to_y);

    function y_to_i() {

        $("span.mohawk_word").each(
            function() {
                $(this).html(
                    $(this).text().replace(/(y[aevu])|(y[oe]n)/ig, function(s) {
                        return '<span class="consonant">'+swap_out_y(s)+'</span>'; 
                        })
                );
            }
        );



        $('.y_to_i').undelegate('click');       
        $('.y_to_i').addClass('i_to_y');
        $('.y_to_i').removeClass('y_to_i');
        $('body').delegate('.i_to_y', 'click', i_to_y);
        //alert('A');
    } //end y_to_i


    function i_to_y(){

        $("span.consonant").each(
            function() {
                $(this).html($(this).text().replace(/i/ig, 
                    function(s) {
                        return swap_out_i(s);
                    }
                )//replace...
                );//html
                //$(this).removeClass('replacement_i');
            }//function(){
        );//each(   

        $('.i_to_y').undelegate('click');
        $('.i_to_y').addClass('y_to_i');
        $('.i_to_y').removeClass('i_to_y');
        $('body').delegate('.y_to_i', 'click', y_to_i);
    }

} //function
); //document ready
  • 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-26T13:25:24+00:00Added an answer on May 26, 2026 at 1:25 pm

    You’re calling delegate on ‘body’ and then calling undelegate on some classes instead of body. So you’re ending up with multiple delegates.

    Working fiddle. http://jsfiddle.net/5HdSC/1/

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

Sidebar

Related Questions

I feel a bit ashamed, this should be simple, but I simply do not
I have a question that I'm ashamed to ask, but I'm going to have
Ok I am pretty ashamed I am posting for help with this, but here
I feel so ashamed about this question, but I can't find a solution, and
I'm quite ashamed to ask a question like this one, but I've been trying
I know this is probably pretty basic, and I'm ashamed for not knowing how
this is probably so trivial that I'm ashamed to be asking this... Why in
Hey everyone, this is an EXTREMELY beginner question, and I'm somewhat ashamed I don't
This one should be easy, and im ashamed i havent figured it out myself
I have a boolean logic question. I have the following if statements that should

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.