Updating “id” attribute of a div programmatically using Javascript

Hello,
I am a new user and thanks for the great theme! I am trying to customise the ID attribute of the various parallax sections on my website so that when clicking on the custom link menu on the top right, the URL changes from from “#shapely_home_parallax-10” → “#awards” (as an example).
Following this suggestion. I tried to add the following code using the widget “Simple Custom CSS and JS” (screenshot attached). I was expecting to see the IDs of two widgets (the 4th and the 2nd) being modified to “my_name” and “my_other_name” as for the script below. Unfortunately nothing changes in the IDs of parallax sections:


jQuery(document).ready(function( $ ){
    var idCount = 1;
$('div').each(function() {
   $(this).attr('id', 'q' + idCount);
   idCount++;
});
$('div#q4').attr('id', 'my_name');
$('div#q2').attr('id', 'my_other_name');

});

I am not familiar with Javascript so I am probably missing something obvious! Any idea on how to make it work? Should I check some options related to “jQuery”?

Best regards
Gio

HI there

Hi there Hope you are having a good day and thank you for your question :slight_smile:
Can i ask why you doing this? this is absolutely not necessary to make such changes

Thanks!
Colorlib Support Team

Hi, thanks for your reply!
I’d like to change the ID of the front-page-widgets because for a one page menu the # links are not optimal and not seo-friendly. Could you suggest a way to achieve that? I’m more than happy to don’t mess around with the java script ?

Kind regards

Hello there,

In order to make these changes you would have to go to Appearance > Editor > CSS and change the CSS in these files.

It is recommended that you have a developer make these changes, you can find one here:

https://colorlib.com/out/envatostudio

Best Regards,
Support

Problem solved! I have found an easy way to add a custom ID to each widget using Widget Options , and it is working as expected.
Best regards,
Gio

Hi, there

Nice, to hear your problem is fixed:) Now I will now close the topic and mark it as resolved. Feel free to contact us again Thanks!