mrkeck Sharing the Love

29Nov/160

Multi-line Javascript

Turns out you can use a backtick (`) to write on multiple lines in javascript

console.log(`
This is on more
than one line
`);

Documentation

13Jan/150

Make buttons act like buttons

By default, buttons are submits, so this should make them act actually like buttons

$('button').attr('type','button');
Filed under: HTML, jquery No Comments
13Apr/140

Cross-Browser Testing

I'm using a Mac so no IE to play with, so it got me looking around.

BrowserStack.com opens a dynamic cloud computer with whatever OS, Browser, and Resolution you would like. The remote Browser has dev tools, even Firebug Lite in IE.

You can take screenshots if you want to as well.

I used this instead of BrowserShots.com (which looks cool too, takes screenshots based on different browsers) because I needed to login to the page I was testing.

13Apr/141

jQuery attr vs prop for Checkbox

attr is iffy

$('.checkbox').attr('checked', true);      //Doesn't work
$('.checkbox').attr('checked', 'checked'); //Sometimes works
$('.checkbox').attr('checked', false);     //Works

but prop works every time

$('.checkbox').prop('checked', true);  //Works
$('.checkbox').prop('checked', false); //Works
Filed under: HTML, jquery 1 Comment
25Feb/140

What is being clicked?

Sometimes with onclick stuff isn't happening as expected so I do

$(document).on('click', function (e) {
	console.log(e.target);
});

which tells me what is receiving the click

Filed under: jquery No Comments
8Jan/140

TableTools in CodeIgniter

The key is using

"sSwfPath": "<?php echo base_url(JS.'media/swf/copy_csv_xls_pdf.swf');?>"

and store the "media/swf/copy_csv_xls_pdf.swf" in the resources JS folder.

"oTableTools": {
  "sSwfPath": "<?php echo base_url(JS.'media/swf/copy_csv_xls_pdf.swf');?>",
     "aButtons": [
	"copy",
	"print",
	{
	  "sExtends":    "collection",
	  "sButtonText": 'Save <span class="caret" />',
	    "aButtons":    [ "csv", "xls", "pdf" ]
	}
     ]
}
6Jan/140

Select2 Width not listening to CSS

When the select2 doesn't change with the css, use $('select').select2({width:'resolve'});
resolve tells it use the css and if there isn't any then guess using javascript.
http://ivaynberg.github.io/select2/#documentation


Ex.

<style>
select{
width: 500px;
}
</style>
<select>
<option>Some Option</option>
</select>
<script>
$('document').ready(function(){
	$('select').select2({width:'resolve'});
});
</script>
Filed under: jquery, select2 No Comments
2Dec/130

jQuery Submit Function Not Working

jQuery submit function error "Property 'submit' of object # is not a function" seems to happen if you use "submit" as a name inside the form you are trying to use the submit() function on.
Ex.

<form id="theFrm">
<button name="submit" type="submit">Save</button>
</form>

Don't use "submit" as a name and $("#theFrm").submit() should work

Filed under: jquery No Comments
19Jun/130

jQuery Uppercase each

$('.model').each(function(i,v){$(this).text($(this).text().toUpperCase());});
Filed under: jquery No Comments
20Apr/130

Use Latest jQuery

<script src="http://code.jquery.com/jquery-latest.min.js"></script>
Filed under: Javascript, jquery No Comments