Add href to a button

0

I have this button and I want to add a href to it, but since the page is made with an "Elementor" wordpress builder but I can not change it directly in the code, so I have tried with functions like this one that I found in other forums but It does not work for me.

var a = document.getElementById('yourlinkId'); 
a.href = "somelink url"

Any way to do it? Thanks

    
asked by Daniel Salinas 08.11.2018 в 22:45
source

2 answers

0

This would be an example HTML:

<input type="button" value="Buscador" class="buscador" id="mibuscador"/>

This would be the JQuery:

    $('.buscador').click(function () {
        window.open = 'https://www.google.com';
    });

or:

    $('#mibuscador').click(function () {
        window.open = 'https://www.google.com';
    });
    
answered by 15.11.2018 в 16:17
0

Good for what I understand you want to make clickable elements

For a single element:

document.getElementById('myBtn').addEventListener('click', () => {
 window.open('tu url')
});

For multiple elements:

const buttons = document.querySelectorAll(".MyClassName");
buttons.forEach((button) => {
    button.addEventListener("click", () =>  window.open('tu url'));
})
    
answered by 15.11.2018 в 16:45