Target blank links with Jquery
Sometimes I need just to update a site and the document type is in Strict mode, for me in the beggining I used to use target=blank on links, but the XHTML 1.0 in Strit mode don´t allow us to use this attribute.
So how to do a site with no warning and errors in the html without tagert=blank? Simple let´s take Jquery do it for us.
The example above I use the rel element, but you can use a class or a id if you want, rel element is more semantic.
Javascript
$('a[@rel$='external']').click(function(){
this.target = "_blank";
});
Html
<a href="http://www.webmista.com" rel="external">webmista</a>
convert unixtime to timestamp
This for me has always been an annoying thing, data is to be made of days, months and years and not a few numbers that have to be converted all the time.
I want to take a look at the database and say “son of a beautiful mother, he made the change and is now he´s saying that he did it three days ago.”
I hope you enjoy.
So there is the php version to convert
Normal date to UNIXTIME
<?php
echo 'date in unixtime :: '.strtotime('1th December 2011 11:12:34 PM (GMT)');
?>
So if you want other type of conversions, for example, just the day or without the time take a look at the php manual to see the many kind of uses
UNIXTIME for default time
<?php
echo 'Default date and time ::'.date('jS F Y h:i:s A (T)', '1256512354');
?>
Mysql version
mysql> SELECT UNIX_TIMESTAMP();
-> 1196440210
mysql> SELECT UNIX_TIMESTAMP('2007-11-30 10:30:19');
-> 1196440219
mysql> SELECT UNIX_TIMESTAMP('2005-03-27 03:00:00');
+---------------------------------------+
| UNIX_TIMESTAMP('2005-03-27 03:00:00') |
+---------------------------------------+
| 1111885200 |
+---------------------------------------+
mysql> SELECT UNIX_TIMESTAMP('2005-03-27 02:00:00');
+---------------------------------------+
| UNIX_TIMESTAMP('2005-03-27 02:00:00') |
+---------------------------------------+
| 1111885200 |
+---------------------------------------+
Check all checkboxes with Jquery
I´ve been working with Jquery for a loooong time, so I will share some experiences.
Above an example how to select all checkboxes with one single checkbox.
It´s a very simple example an then you could made a lot of modifications.
html
<div> <ul> <li><input class="chkAll" type="checkbox" name="" value="all" /> Select All </li> <li><input class="chk" type="checkbox" name="" value="1" /> item 1</li> <li><input class="chk" type="checkbox" name="" value="2" /> item 2</li> <li><input class="chk" type="checkbox" name="" value="3" /> item 3</li> </ul> </div>
js
$(".chkAll").click(function(){//remember that this will work in the element whith the class chkAll
if( $(this).is(':checked') ){
$(this).parent().parent().find(':checkbox').attr('checked', true);
}else{
$(this).parent().parent().find(':checkbox').attr('checked', false);
}
})