Skip to main content

Posts

Showing posts from August, 2012

Disable a hyperlink using javascript - jquery

I was working on an iOS application where we were displaying HTML content. We did not have control over these HTMLs and because of these we were facing lots of issues. One of the issue was handling of hyperlinks, we needed to handle the navigation ourselves. You can disable the hyperlink using the preventDefault() javascript function. Below is the sample using which you can disable the default behavior of a hyperlink. <html> <head> <script src="jquery-1.5.1.min.js" type="text/javascript"></script> <style></style> <script>   $(document).ready(function () {   $('a').click(function(e) {     e.preventDefault();             //do other stuff when a click happens     return false;  //In few browsers you will need to return false at the end     }); }); </script> </head> <body> <a href="www.google.com"> Google!!!</a> </body> </html> Note : In fe

Change selection background and color using css

It is always nice to have a cool UI for our website. Changing the background and foreground color of selection can do wonders sometimes. In this post I will show you how you can achieve that. We can do this easily using CSS3. It provides us with ::selection selector. Safari supports ::selection and firefox supports   ::-moz-selection.  Webkit browsers supports ::-webkit-selection. With time many browsers have started supporting ::selection itself. .content::selection  {     background: #E01624;     color:White; } .content::-moz-selection  {      background: #E01624;      color:White; } .content::-webkit-selection {      background: #E01624;      color:White; } .content {       overflow:hidden; } In HTML I have div with class as content. 

How to get html tag name of an html element using jQuery

Some times it is needed to get the tag name of an element. You can use below mentioned script to get that. <html> <head> <script src="jquery-1.5.1.min.js" type="text/javascript"></script> <script>   $(document).ready(function () {     alert( $('#someElement').attr('tagName') );   )}; </script> <body> <a  href="#">click to get tag name </a> <div id= 'someElement'> You want tag name of this element. </div> </body> </html