I am using this fancy little JavaScript to highlight a field as the user hovers over it. Could you please tell me if there is a way of adding an onclick
function which will act as a link and go to a URL?
<script> $(function() { $('tr').hover(function() { $(this).css('background-color', '#eee'); $(this).contents('td').css({'border': '0px solid red', 'border-left': 'none', 'border-right': 'none'}); $(this).contents('td:first').css('border-left', '0px solid red'); $(this).contents('td:last').css('border-right', '0px solid red'); }, function() { $(this).css('background-color', '#FFFFFF'); $(this).contents('td').css('border', 'none'); $('a#read_message.php').click(function(){ URL(); }); }); }); </script>
Using onclick Event: The onclick event attribute works when the user click on the button. When mouse clicked on the button then the button acts like a link and redirect page into the given location. Using button tag inside <a> tag: This method create a button inside anchor tag.
This is a type of JavaScript link - the onclick attribute defines a JavaScript action when the 'onclick' event for the link is triggered (i.e. when a user clicks the link) - and there is a URL present itself in the onclick attribute.
In JavaScript, to go to URL with onclick, you can use the “window. open()” method to open the window with the specified “URL” or apply the “window. location” object method to specify the location of the specified URL and the “window.
The plain HTML way is to put it in a <form> wherein you specify the desired target URL in the action attribute. If necessary, set CSS display: inline; on the form to keep it in the flow with the surrounding text. Instead of <input type="submit"> in above example, you can also use <button type="submit"> .
Try
window.location = url;
Also use
window.open(url);
if you want to open in a new window.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With