Change Title of link in Navigation Block

Course Queries Syllabus Queries 2 years ago

0 2 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on Syllabus Queries related to Course Queries. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (2)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago


I've tried a few different ways to change the title of a link within the navigation block through Javascript, but to no avail.

Is there something that I am missing?

Here's the original code via the site:

 id="left-side" href="https://forum.tuteehub.com/tag/class">class="ic-app-course-menu list-view" style="display: block">
          <href="https://forum.tuteehub.com/tag/span">span id="section-tabs-header-subtitle" href="https://forum.tuteehub.com/tag/class">class="ellipsis">Sandboxhref="https://forum.tuteehub.com/tag/span">span>
         role="navigation" aria-label="Courses Navigation Menu"> id="section-tabs"> href="https://forum.tuteehub.com/tag/class">class="section"> href="/courses/16289" title="Home" href="https://forum.tuteehub.com/tag/class">class="home" tabindex="0">Home href="https://forum.tuteehub.com/tag/class">class="section"> href="/courses/16289/external_tools/375" title="Course Syllabus" href="https://forum.tuteehub.com/tag/class">class="context_external_tool_375" tabindex="0">Course Syllabus href="https://forum.tuteehub.com/tag/class">class="section"> href="/courses/16289/modules" title="Modules" href="https://forum.tuteehub.com/tag/class">class="modules active" tabindex="0">Modules href="https://forum.tuteehub.com/tag/class">class="section"> href="/courses/16289/grades" title="Grades" href="https://forum.tuteehub.com/tag/class">class="grades" tabindex="0">Grades href="https://forum.tuteehub.com/tag/class">class="section"> href="/courses/16289/users" title="People" href="https://forum.tuteehub.com/tag/class">class="people" tabindex="0">People
    

Here is the Javascript I'm using to attempt to change the title "Course Syllabus" to just "Syllabus"

 

if (ENV.current_user_roles.indexOf("admin") < 1){  
  $( document ).ready(function() {  
  document.querySelector('#section-tabs a.context_external_tool_375').innerHTML = "Syllabus";  
});  
}  
profilepic.png
manpreet 2 years ago


You have the exact right idea, and your code should work as expected. However, your conditional to check whether the user is an admin should really come inside of your $(document).ready(). Having said that, it will still trigger the way you have it now.

As such, there can only be two possible things causing your script not to work for you:

  • You have forgotten to include jQuery
  • Your condition is not evaluating to be truthy

Including jQuery and substituting the condition for one that is always true shows the name change working, as can be seen in the following example:

 

$(document).ready(function() {
  if (1) {
    document.querySelector('#section-tabs a.context_external_tool_375').innerHTML = "Syllabus";
  }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js">script>

 id="left-side" class="ic-app-course-menu list-view" style="display: block">
   id="section-tabs-header-subtitle" class="ellipsis">Sandbox
   role="navigation" aria-label="Courses Navigation Menu">
     id="section-tabs">
       class="section"> href="/courses/16289" title="Home" class="home" tabindex="0">Home
       class="section"> href="/courses/16289/external_tools/375" title="Course Syllabus" class="context_external_tool_375" tabindex="0">Course Syllabus
       class="section"> href="/courses/16289/modules" title="Modules" class="modules active" tabindex="0">Modules
       class="section"> href="/courses/16289/grades" title="Grades" class="grades" tabindex="0">Grades
       class="section"> href="/courses/16289/users" title="People" class="people" tabindex="0">People
    
  

0 views   0 shares

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.

Important Course Queries Links