Skip to content

Instantly share code, notes, and snippets.

View longjasonm's full-sized avatar

Jason Long longjasonm

View GitHub Profile
$('form :input').each(function(index, elem) {
var eId = $(elem).attr('id');
var label = null;
if (eId && (label = $(elem).parents('form').find('label[for='+eId+']')).length === 1) {
$(elem).attr('placeholder', $(label).html());
@salcode
salcode / gist:6912619
Last active November 8, 2023 01:11
jQuery function to remove all "data-" attributes from a given element
// Note: This is an improved version provided by @laurentmuller in the comments below.
// removes all data attributes from a target element
// example: removeDataAttributes('#user-list');
function removeDataAttributes(target) {
var $target = $(target);
// Loop through data attributes.
$.each($target.data(), function (key) {
// Because each key is in camelCase,
@varemenos
varemenos / getparam.js
Created April 29, 2012 03:50 — forked from alkos333/gist:1771618
JQuery - GET URL Parameter value
// Given a query string "?to=email&why=because&first=John&Last=smith"
// getUrlVar("to") will return "email"
// getUrlVar("last") will return "smith"
// Slightly more concise and improved version based on http://www.jquery4u.com/snippets/url-parameters-jquery/
function getUrlVar(key){
var result = new RegExp(key + "=([^&]*)", "i").exec(window.location.search);
return result && unescape(result[1]) || "";
}
@mozz100
mozz100 / marketo_interesting_moment.js
Created January 30, 2012 12:03
Marketo Sales Insight - notify sales team which file was downloaded
/* Use the Munchkin API to record a 'visitWebPage' event (see http://community.marketo.com/MarketoArticle?id=kA050000000Kyr7). Set the url of the visitWebPage event to the url of the download. I found that I had to make the link open in a new window, otherwise the Munchkin never manages to 'call home'...
I did it with jQuery. Replace $jq with a reference to a valid jQuery object in the code below.
We use a separate subdomain for Marketo-hosted landing pages and resources (in common with most users, I suspect). Since we wanted to track downloads for any PDF or PPT file within that domain, the jQuery selector pretty much wrote itself. It's case sensitive, but could easily be extended or modified to work around that - wasn't necessary for me.
Opening the links in a new window seems to help with the tracking. If the new page loads too quickly, then it seemed as if the event handler code didn't get called. Leaving the original window open avoids this (I set target="_blank").
*/
@makeusabrew
makeusabrew / label-to-placeholder.js
Created May 22, 2011 18:32
Simple jQuery snippet to convert form labels into inline placeholders
$("form :input").each(function(index, elem) {
var eId = $(elem).attr("id");
var label = null;
if (eId && (label = $(elem).parents("form").find("label[for="+eId+"]")).length == 1) {
$(elem).attr("placeholder", $(label).html());
$(label).remove();
}
});