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

This forum is for all Flare issues not related to any of the other categories.

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

Postby kel322 on Tue Jan 11, 2022 2:15 pm

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: 32
Joined: Tue Jan 03, 2017 12:56 pm

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

Postby kel322 on Thu Jan 13, 2022 2:20 pm

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
});
kel322
Propeller Head
 
Posts: 32
Joined: Tue Jan 03, 2017 12:56 pm


Return to Flare's General Discussion

Who is online

Users browsing this forum: No registered users and 10 guests