Hi. I wondered if anyone can help- I am trying to hide an element from the header of home page and keep for others. I followed this: Velo Tutorial: Hiding an Element on Certain Pages | Help Center | Wix.com but it hides it on all other pages. Also checked I put code on page not site. Any help please!
Try this:
import wixLocation from 'wix-location';
$w.onReady(function() {
if (wixLocation === '/') {
$w('#myElement').collapse();
} else {$w('#myElement').expand();
} );
Thank you David, much appreciated. Still doesn’t work- Its says 7 has an unexpected token…
@eclectic_arts Could you please post a screenshot with the element, code, and error?
Sorry, forgot a bracket:
import wixLocation from ‘wix-location’;
$w.onReady( function () {
if (wixLocation === ‘/’) {
$w(‘#myElement’).collapse();
} else {$w(‘#myElement’).expand();}
} )
thank you. Just realised- do I need to put anything in ‘Wix location’?
Nope, it should work as is, but let me know if throws back more errors.
no more errors but Wix location is red and it doesn’t work:(
The element is in the header, so maybe its not possible?
@eclectic_arts Can you take a screenshot of the element itself?
Try show instead of expand, and hide instead of collapse…then send me a link to your website if it doesn’t work…I suspect it might be an ongoing Wix issue.
Wait, actually hang on. This code needs to be in the site code, not page code. I just reread your first post.
ah sadly still not- tried all combinations. Thanks so much for trying, very kind. website is: https://cassandratomaz.wixsite.com/lucylanefox
try substituting “/” for “/lucylanefox”
If this works, then my suspicions are correct and this is the ongoing Wix issue.
actually working solutionfor (on site tab) :
import wixLocation from 'wix-location';
$w.onReady(function () {
const location = wixLocation.path.join("/")
if (location === '') {
$w('#button4').hide();
} else if (location === "contact") {
$w('#button4').hide();
} else {
$w('#button4').show();
}
});