jQuery to JS not workin
4 posters
Page 1 of 1
jQuery to JS not workin
Hello,
I have this jQuery code
I've tried testing JS with alert command, and the code runs, but it simply doesn't manipulate the content of the "#underNav".
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> • </li>
<li><a href="/memberlist?mode=lastvisit&order=DESC&submit=Ok&tt=1&username">Last Visited</a> • </li>
<li><a href="/memberlist?mode=username&order&submit=Ok&tt=1&username">Members by name</a> • </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);
}
});
- 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> • </li><li><a href="/memberlist?mode=lastvisit&order=DESC&submit=Ok&tt=1&username">Last Visited</a> • </li><li><a href="/memberlist?mode=username&order&submit=Ok&tt=1&username">Members by name</a> • </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;
}
I've tried testing JS with alert command, and the code runs, but it simply doesn't manipulate the content of the "#underNav".
Last edited by BloodDrunk on May 2nd 2017, 7:33 pm; edited 1 time in total
Re: 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.
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.
Re: jQuery to JS not workin
Hey,
The problem is that your code is executing before the document is ready. All JavaScript on Forumotion is executed in the <head> section, so trying the retrieve an element before it has been parsed will throw an error. ( i.e. "cannot set innerHTML property of null" where null is "x" ) Wrap your code with this and it should work without issue :
It's pretty much the equivalent of jQuery's document ready function. i.e.
and the shorthand version :
The problem is that your code is executing before the document is ready. All JavaScript on Forumotion is executed in the <head> section, so trying the retrieve an element before it has been parsed will throw an error. ( i.e. "cannot set innerHTML property of null" where null is "x" ) Wrap your code with this and it should work without issue :
- Code:
document.addEventListener('DOMContentLoaded', function () {
// code to execute when the document is ready
});
It's pretty much the equivalent of jQuery's document ready function. i.e.
- Code:
$(document).ready(function () {
});
and the shorthand version :
- Code:
$(function() {
});
Re: jQuery to JS not workin
Hey Angie,
So that's why JS doesn't work, and jQuery does..
But this still brings me back to the problem, even if I use JS. How do I avoid that delay (or can it be avoided?) I want to change the content while the page is loading, because once it fully loads, it's very noticeable how elements get changed and that doesn't look pretty.
You can check it yourself: www.nfssecrets.tk
Just click any navigation button and see how bad it performs.. (bad, as in quite the delay, atleast for me).
So that's why JS doesn't work, and jQuery does..
But this still brings me back to the problem, even if I use JS. How do I avoid that delay (or can it be avoided?) I want to change the content while the page is loading, because once it fully loads, it's very noticeable how elements get changed and that doesn't look pretty.
You can check it yourself: www.nfssecrets.tk
Just click any navigation button and see how bad it performs.. (bad, as in quite the delay, atleast for me).
Re: jQuery to JS not workin
You could set the opacity of the page to 0 from the css:BloodDrunk wrote:How do I avoid that delay (or can it be avoided?) I want to change the content while the page is loading, because once it fully loads, it's very noticeable how elements get changed and that doesn't look pretty.
|
Guest- Guest
Re: jQuery to JS not workin
Actually, that is a very good idea! I'll try it out and see how that'll workout.Wolfuryo wrote:You could set the opacity of the page to 0 from the css:BloodDrunk wrote:How do I avoid that delay (or can it be avoided?) I want to change the content while the page is loading, because once it fully loads, it's very noticeable how elements get changed and that doesn't look pretty., then turn it back to 1 just after the page loads and javascript changes stuff.
- Code:
body{opacity:0.0}
Re: jQuery to JS not workin
Good luck!BloodDrunk wrote:Actually, that is a very good idea! I'll try it out and see how that'll workout.Wolfuryo wrote:You could set the opacity of the page to 0 from the css:BloodDrunk wrote:How do I avoid that delay (or can it be avoided?) I want to change the content while the page is loading, because once it fully loads, it's very noticeable how elements get changed and that doesn't look pretty., then turn it back to 1 just after the page loads and javascript changes stuff.
- Code:
body{opacity:0.0}
Guest- Guest
Re: jQuery to JS not workin
This could work I think, does it "feel" bad? Could you test it out little bit, I'm not sure whether to use that approach or not.
Re: jQuery to JS not workin
I used that method on my forum for quite a lot of time and no one seemed to be bothered 'bout it, or even notice it.
Guest- Guest
Re: jQuery to JS not workin
I tried using it, but it causes some other problems, so I guess I'll just have it the way it is, until I figure what could be done to "fasten" it..
Re: jQuery to JS not workin
Locked as Requested
Lost Founder's Password |Forum's Utilities |Report a Forum |General Rules |FAQ |Tricks & Tips
You need one post to send a PM.
You need one post to send a PM.
When your topic has been solved, ensure you mark the topic solved.
Never post your email in public.
Similar topics
» Anchor not workin :/
» I have need some help for jquery !
» smilies not workin!
» Jquery doubt
» JQuery Help
» I have need some help for jquery !
» smilies not workin!
» Jquery doubt
» JQuery Help
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum