Manixat Posted December 17, 2012 Share Posted December 17, 2012 Hey, I want to place an advertisement on my pages' HTML tag BACKGROUND-IMAGE, but the problem is I can't figure out how to detect a click ? Quote Link to comment https://forums.phpfreaks.com/topic/272085-html-background-click/ Share on other sites More sharing options...
MDCode Posted December 17, 2012 Share Posted December 17, 2012 You can wrap it in a div or class then use a jquery call: $("#div").click(function() // or$(".class").click(function() { { do something }); Quote Link to comment https://forums.phpfreaks.com/topic/272085-html-background-click/#findComment-1399823 Share on other sites More sharing options...
Manixat Posted December 17, 2012 Author Share Posted December 17, 2012 yeah that's obvious but that would be the solution if there's no way of detecting a click on the html element where there's nothing above it ( in the 3D schema ) Quote Link to comment https://forums.phpfreaks.com/topic/272085-html-background-click/#findComment-1399825 Share on other sites More sharing options...
Petermichael703 Posted December 13, 2013 Share Posted December 13, 2013 hi .manixat To accomplish this, you may get solutions like adding <a> around <div>. But it won’t be a good practice as per standard. Finally you may end up with replacing <div> with <IMG>. But you will never get the desired output. But my solution is quite simple. Make it clickable with JavaScript. Simple Jquery Solution is $(document).ready(function() {$("div.js-ad-home-page-background").click(function(event){window.open('LINK_TO_ADVERTISE');});}); Common Issues Ad links will won’t work if there is no JavaScript(which is not at all happen now days) and if any JS error in page. Which are common. So make sure that no script error before this jQuery snippet Note: Make sure that you have added jquery.js let me know if it helps Quote Link to comment https://forums.phpfreaks.com/topic/272085-html-background-click/#findComment-1462278 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.