Hyperlinking Boxes

Hey, i am trying to hyperlink multiple boxs on my homepage to internal webpages.
Using the code below i am able to link one box nicely, however when i try to add more hyperlinks to other boxes (repeating code below ) i get error messages, can someone please help ?

import wixLocation from 'wix-location';
$w.onReady(function () {
    $w("#box64").onClick( (event) => {
        wixLocation.to("/post/nokomis-lodge");
    })

});

Post the code that you have for the other boxes so we can see what you are trying to do. What errors are you getting?

Thanks for responding Yisrael - im repeating the code like so, I have 10 hyperlinks to add to 10 boxes, hope this makes sense?

import wixLocation from 'wix-location';
$w.onReady(function () {
    $w("#box64").onClick( (event) => {
        wixLocation.to("/post/nokomis-lodge");
    })
});


import wixLocation from 'wix-location';
$w.onReady(function () {
    $w("#box61”).onClick( (event) => {
        wixLocation.to("/post/pugh-house");
    })
});

You should only have one import statement, and one onReady() function. Something like this:

import wixLocation from 'wix-location';

$w.onReady(function () {
    $w("#box64").onClick( (event) => {
        wixLocation.to("/post/nokomis-lodge");
    })
    $w("#box61").onClick( (event) => {
        wixLocation.to("/post/pugh-house");
    })
});

Please realize that you can’t just “copy and paste” code and expect it to work. You need to understand what’s happening if you expect to be able to write code that does what you want.

To learn about programming with Velo, read the following articles that will help you start working with Velo:

  • About Velo by Wix - what Velo is and what features it has.

  • Getting Started with Velo by Wix - step-by-step tutorial on how to start using Velo.

  • Onboarding to Velo by Wix - introduction to Velo with short tutorials.

thanks Yisreal. Since upgrading from Wix to editorX I have lost a lot of basic features (hyperlinking boxes to pages on my website is the last thing I thought I’d have issues with!). As a result I am teaching myself basic code to find work arounds. Before messaging I have looked through the Velo, Code Academy, Wix help centre etc but cannot find a solution. I appreciate your understanding and patience.

Unfortunately the code you recommended trying does not work and I get the error message:
public/pages/c1dmp.js: Unterminated string constant. (7:7)

5 | wixLocation.to(“/post/nokomis-lodge”);
6 | })

7 | $w(“#box61”).onClick( (event) => { | ^
8 | wixLocation.to(”/post/pugh-house");
9 | })
10 | });

As you can see in the error report, you have a problem in line 7. The closing quote mark is incorrect. You want " and not ”.

You don’t want this:

$w("#box61”).onClick((event)=>{

You want this:

$w("#box61").onClick((event)=>{

Copy my code again and give it another try.

Fantastic! thanks for pointing out the error - my site is ready for launch :slight_smile:

Hi! Im having the same question. My web is a portfolio, i want to link each containers to matching project pages. Like linking box12 to page A. at the moment my page A is still empty but I’m placing photos and texts in.

So what can I write in the wixlocation? i tried to put in (“/A/”) but it doesnt work.

import wixLocation from ‘wix-location’; $w.onReady(function () { $w(“#box12”).onClick( (event) => { wixLocation.to (“/A/”); }) });

to be clearer, i just want to link to a normal page, with photos and text sth like behance. Not a multi products/posts page. I dont really know what to do :frowning: