Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #1173002

    Hello,

    I have been told that i need to add an onlick event to a bunch of HTML links on my Enfold website. However whenever i click save the code disappears. The code is located in a text block.

    See private section for detail.

    What is causing this and how do i fix it?

    #1173200

    Hey w_archer,

    The links you posted are the same as far as I can see, could you post a link to where we can see the actual element and try to explain a bit further please?

    Best regards,
    Rikard

    #1173729

    Hello,

    For some reason it turned the HTML into an actual link.

    i have reattached below.

    #1173730

    nope its still doing it…

    How do i attach HTML without it being read as HTML??

    #1173732

    see below

    #1174000

    Hi,
    Please try pasting your link into a plain text file as html and upload it to DropBox and link to it here.
    I assume you are trying an on click event like this:

    <a href="https://google.com" onClick='alert("You clicked the link")'>on click link</a>

    If true then add this to your text element in the “text” tab and not in the “visual” tab, but the next time you edit the element the code will be striped.
    To get around this use a link with a custom ID instead and add the event function to your functions.php or in a “code block” element on the page. For example, this would be your link:

    <a href="#" id="myonclick">on click link</a>

    and this would be in your code block element:

    <script>
    (function($){
    $(window).load(function() {
    $("#myonclick").on('click', function() {
      alert("You clicked the link");
      window.location = "https://www.google.com";
    })
    });
    })(jQuery);
    </script>

    If you add this in your functions.php then change it to this:

    function custom_script(){
      ?>
      <script>
    (function($){
    $(window).load(function() {
    $("#myonclick").on('click', function() {
      alert("You clicked the link");
      window.location = "https://www.google.com";
    })
    });
    })(jQuery);
    </script>
    <?php
    }
    add_action('wp_footer', 'custom_script');

    Best regards,
    Mike

    #1174702

    Perfect that worked!

    I’m not that good with Javascript, how can i convert this to say the code below in the private area? Apparently is a SEO tracking code

    #1174872

    Hi,
    Glad to hear, so to use your onClick for a phone link it would be:

    (function($){
    $(window).load(function() {
    $("#myonclick").click( function() {
            ga('send', 'event', 'Phone_Click', 'Home_Page', '1300_668_387');
            window.location = "tel://1-555-555-5555";
    })
    });
    })(jQuery);

    be sure to adjust the phone number in the code.

    Best regards,
    Mike

    #1175224

    Perfect!

    Thanks a bunch, much appreciated

    #1175226

    Hi,
    Glad we were able to help, we will close this now. Thank you for using Enfold.

    For your information, you can take a look at Enfold documentation here
    For any other questions or issues, feel free to start new threads in the Enfold forum and we will gladly try to help you :)

    Best regards,
    Mike

Viewing 10 posts - 1 through 10 (of 10 total)
  • The topic ‘Onclick event on HTML link dissapears on save’ is closed to new replies.