Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

298
Views
how to remove highlight from only one selection using mark.js

I've created a form that highlights matching text on entered in a textarea on the page as you make selections on the checkboxes. It seems to work properly when you are checking the checkboxes, but as soon as you have more then one checkbox checked and then uncheck a single checkbox, all highlights get removed. I would like it to only remove the highlight of the unchecked box when it is changed from checked to unchecked.

I'm fairly new to JavaScript so I'm not sure if I'm missing something obvious here or not but I am stumped as to why I'm getting this behavior.

Here is an example function handling the highlight on a single checkbox. You can see my full code in the JS fiddle link here: https://jsfiddle.net/gosem01/kf8az926/1/

function highlightArrowsOnCheck() {
  var instanceArrows = new Mark(highlightedParagraph);
  var options = {
    "debug": true,
    "log": window.console
  };

  if (checkedArrows.checked) {
    instanceArrows.markRegExp(/\«|»/g, options);
  } else {
    instanceArrows.unmark(options);
  }
}

mark.js docs: https://markjs.io/

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Use className parameter to mark/unmark a group

https://markjs.io/#parameters

function highlightArrowsOnCheck() {
  var instanceArrows = new Mark(highlightedParagraph);
  var options = {
    "className": "arrows", // added
    "debug": true,
    "log": window.console
  };

  if (checkedArrows.checked) {
    instanceArrows.markRegExp(/\«|»/g, options);
  } else {
    instanceArrows.unmark(options);
  }
}

Working Demo

Note: togglecheckall function is simplified by triggering event programmatically.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!