-
AuthorPosts
-
January 14, 2020 at 1:03 am #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?
January 14, 2020 at 10:45 am #1173200Hey 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,
RikardJanuary 14, 2020 at 11:29 pm #1173729Hello,
For some reason it turned the HTML into an actual link.
i have reattached below.
January 14, 2020 at 11:31 pm #1173730nope its still doing it…
How do i attach HTML without it being read as HTML??
January 14, 2020 at 11:34 pm #1173732see below
January 15, 2020 at 2:24 pm #1174000Hi,
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,
MikeJanuary 15, 2020 at 10:52 pm #1174702Perfect 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
January 16, 2020 at 12:03 pm #1174872Hi,
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,
MikeJanuary 17, 2020 at 1:46 am #1175224Perfect!
Thanks a bunch, much appreciated
January 17, 2020 at 2:54 am #1175226Hi,
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 -
AuthorPosts
- The topic ‘Onclick event on HTML link dissapears on save’ is closed to new replies.