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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:25:26+00:00 2026-06-10T07:25:26+00:00

I use codemirror and jquery to simulate an xml-editor in the browser. Some xml-Tags

  • 0

I use codemirror and jquery to “simulate” an xml-editor in the browser. Some xml-Tags include an “on”-attribute with two possible values (true or false). Would it be possible to toggle these values at an onclick event? Is a codemirror/jquery plugin available?

EDIT :

self-coded solution.

function attrtoggle(){
    var pos = editor.getCursor();
    var line = editor.getLine(pos.line);
    var index = line.indexOf("on=");

    if(index > 0){
        //define range 
        if ( pos.ch -3 < index || pos.ch - 9 > index)
            return false;

        var len = 10;
        var replace_pos = index + 4;

        if(line.charAt(replace_pos) == "t"){
            //insert false
            line = line.replace('true', 'false');
        } else{
            //insert true
            line = line.replace('false', 'true');
        }
        edited = pos.line;
        editor.setLine(pos.line, line);
    }
}

Just add an event-handler for the onclick event

$(".CodeMirror").attr("onclick","javascript:attrtoggle()");
  • 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-10T07:25:27+00:00Added an answer on June 10, 2026 at 7:25 am

    By far not perfect (bad design and so on) , but it works as expected:

    Just trigger the function at an onclick event.

    function attributeToggle(){
    
        var transitions = {
            "on": {
                "false":"true",
                "true":"false"
            }
        }
    
    
        var pos = editor.getCursor(); // object {line, ch}
        var token = editor.getTokenAt(pos);
        var line = editor.getLine(pos.line);
    
        try{
    
            var prev_pos = token.start - 1;
            var prev_token = editor.getTokenAt({'line':pos.line, 'ch':prev_pos});
    
            if(prev_token.className == "attribute")
                var attr = prev_token.string;
            else
                return false;
    
            if(typeof transitions[attr] === "undefined") //nothing to replace
                return false;
    
            var current_val = token.string.toLowerCase().replace(/(['"])/g, "");
    
    
            if(typeof transitions[attr][current_val] === "undefined")
                return false;
    
            var line_new =  line.substring(0, token.start) + \
     "\"" + transitions[attr][current_val] + "\"" +  line.substring(token.end);
    
            editor.setLine(pos.line, line_new);
    
    
        } catch (e){
            console.log(e);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use a component called Codemirror for in-browser source code editing. It
i try to use codemirror in a jquery ui dialog. here you can see
I need to write my own code editor in browser. I found CodeMirror but
Use Elixir and have two entities -- Voter and Candidate -- with many to
Use default: <input type=radio name=restype value=resdef onfocus=document.getElementById('resupload').disabled = true; document.getElementById('resadres').disabled = true; checked=checked /><br
Use case: we have some project meta-data files which we want tracked, but are
i try to get the name attribute from an element and use that string
use case is simple: I want to run some boiler plate code before each
Use case is this: I want to unit test (in browser, QUnit or something
I am trying to use jquery to override the default tabbing navigation. I cannot

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.