Reputation: 38
I've been trying to swap out a link on a page using javascript and seem to have hit a wall. I believe the way my URL is encoded might be at fault.
var a = document.querySelector('a[href="https://sis.harpercollege.edu/class-schedule/class-schedule.html?course=230&subject=BIO&term=202295&_gl=1*1wa2tu7*_ga*MTA4NzY5ODQ3LjE2MjQ4ODM4NjY.*_ga_2575BXQHNN*MTY0OTY5MTI0NC4yNDYuMS4xNjQ5Njk1NDY0LjA"]');
if (a) {
a.setAttribute('href', 'https://sis.harpercollege.edu/class-schedule/class-schedule.html?course=130&subject=BIO&term=202295&_gl=1*1wa2tu7*_ga*MTA4NzY5ODQ3LjE2MjQ4ODM4NjY.*_ga_2575BXQHNN*MTY0OTY5MTI0NC4yNDYuMS4xNjQ5Njk1NDY0LjA')
}
<a title="View the schedule for BIO230 for Summer 2022" href="https://sis.harpercollege.edu/class-schedule/class-schedule.html?course=230&subject=BIO&term=202295&_gl=1*3cwusx*_ga*MTA4NzY5ODQ3LjE2MjQ4ODM4NjY.*_ga_2575BXQHNN*MTY0OTY5MTI0NC4yNDYuMS4xNjQ5Njk2MTkzLjA" target="_blank">Summer 2022</a>
Upvotes: 0
Views: 44
Reputation: 187
You're trying to select this a[href="https:///sis.harpercollege.edu/class-schedule/class-schedule.html?course=230..... but in your html you have this <a title="View the schedule for BIO260 for Summer 2022" href="https:///sis.harpercollege.edu/class-schedule/class-schedule.html?course=260
Basically The code in your condition will never get executed because query selector doesn't find an a tag with that href attribute value.
Upvotes: 1