Current date/time is April 19th 2024, 6:22 am

Search found 2 matches for underNav

jQuery to JS not workin

It's supposed, depending on which page you currently are, display appropriate HTML content in #underNav.
It's not complete code yet.

The reason I want to use JS is because it's faster than jQuery. jQuery gives noticeable delay, unlike JS, and it bothers me really much.
by BloodDrunk
on April 28th 2017, 1:55 pm
 
Search in: Garbage
Topic: jQuery to JS not workin
Replies: 12
Views: 627

jQuery to JS not workin

Hello,

I have this jQuery code
Code:
$(document).ready(function(){
  var path = location.pathname;
  var links_members = `<ul class="linklist">
             <li><a href="/memberlist?mode=posts&order=DESC&submit=Ok&tt=1&username">Most Messages</a>&nbsp;&bull;&nbsp;</li>
                        <li><a href="/memberlist?mode=lastvisit&order=DESC&submit=Ok&tt=1&username">Last Visited</a>&nbsp;&bull;&nbsp;</li>
                        <li><a href="/memberlist?mode=username&order&submit=Ok&tt=1&username">Members by name</a>&nbsp;&bull;&nbsp;</li>
                        <li><a href="/memberlist?mode=groups&order&submit=Ok&username">Member in usergroups</a></li>
                      </ul>`;
 
if(path.indexOf("/u") >= 0 || path == "/privmsg" || path == "/profile" || path == "/" || path == "/groups" || path == "/register" || path == "/login"){
  $("#underNav").html("");
} else if (path == "/memberlist"){
  $(".user-relative-forum-statistics").html(links_members);
}
});

which I've rewritten to JS like the following:
Code:
//Variables
var path = location.pathname;
var x = document.getElementById("underNav");
var links_members = '<ul class="linklist"><li><a href="/memberlist?mode=posts&order=DESC&submit=Ok&tt=1&username">Most Messages</a>&nbsp;&bull;&nbsp;</li><li><a href="/memberlist?mode=lastvisit&order=DESC&submit=Ok&tt=1&username">Last Visited</a>&nbsp;&bull;&nbsp;</li><li><a href="/memberlist?mode=username&order&submit=Ok&tt=1&username">Members by name</a>&nbsp;&bull;&nbsp;</li><li><a href="/memberlist?mode=groups&order&submit=Ok&username">Member in usergroups</a></li></ul>';

//Function
if (path.indexOf("/u") >= 0 || path == "/privmsg" || path == "/profile" || path == "/" || path == "/groups" || path == "/register" || path == "/login"){
  x.innerHTML = "";
}
else if (path == "/memberlist"){
          x.innerHTML = links_members;
}

but the JS code doesn't seem to work, while jQuery works just fine.
I've tried testing JS with alert command, and the code runs, but it simply doesn't manipulate the content of the "#underNav".
by BloodDrunk
on April 28th 2017, 1:41 pm
 
Search in: Garbage
Topic: jQuery to JS not workin
Replies: 12
Views: 627

Back to top

Jump to: