The way you suggest doing this, it won’t ever be secure. If I understand you, just disabling Javascript would spoil the security.
What you’d need to do is run a script that uses an AJAX request to query for and then add data to the page, but only if the user is logged in. That would fail safe if Javascript were disabled.
However, that is also a very labor/server intensive way to do this. My suggestion would be to conditionally add the data to the page via PHP before the page is rendered at all.