I\'m using Bootstrap and the following doesn\'t work:
Blah Blah
-
A much more flexible solution is to target anything with the data-href attribute. This was you can reuse the code easily in different places.
Col 1
Col 2
Then in your jQuery just target any element with that attribute:
jQuery(document).ready(function($) {
$('*[data-href]').on('click', function() {
window.location = $(this).data("href");
});
});
And don't forget to style your css:
[data-href] {
cursor: pointer;
}
Now you can add the data-href attribute to any element and it will work. When I write snippets like this I like them to be flexible. Feel free to add a vanilla js solution to this if you have one.
- 热议问题