Batch create / assign ids to <h2> and <h3> tags?

This forum is for all Flare issues not related to any of the other categories.
Post Reply
kel322
Propeller Head
Posts: 34
Joined: Tue Jan 03, 2017 12:56 pm

Batch create / assign ids to <h2> and <h3> tags?

Post by kel322 »

Hello,
Does anyone know of a way to automatically create ids for certain tags within Flare?

I'm working on adding a script to our documentation that allows users to click a button that will create and copy a link to a specific section of the page (similar to Chrome's new dynamic linking extension but not quite as advanced). The script uses the ids of h2 and h3 tags. We probably have nearly a thousand h2 and h3 tags that don't have ids. Doing this by hand will take for-e-ver!

Thanks!
kel322
Propeller Head
Posts: 34
Joined: Tue Jan 03, 2017 12:56 pm

Re: Batch create / assign ids to <h2> and <h3> tags?

Post by kel322 »

Just an FYI for anyone who is curious. I did not find a fast way to do this within Flare. But I did find a script that will add the ids when the page loads, which works just fine with the other script that I am using to create and copy links to specific sections of the webpage.

Code: Select all

var $headers = $('body h2, h3');
$headers.attr("id", function() {
  return $(this)
    .text() // get the h2, h3 text
    .trim() // remove spaces from start and the end
    .toLowerCase() // optional
    .replace(/\s/g, '-'); // convert all spaces to dashes
});
Post Reply