How to create a HTML tag, using an object of properties.
[code]$(‘#somediv’).append($(‘<a/>’, {href: ‘#’, id: ‘dothing’, text: ‘Do Thing’}));[/code]
You are currently browsing the blog archives for December, 2013.
How to create a HTML tag, using an object of properties.
[code]$(‘#somediv’).append($(‘<a/>’, {href: ‘#’, id: ‘dothing’, text: ‘Do Thing’}));[/code]
Tags: Code, dom, html, javascript, jquery, object
Posted in Code | No Comments »
Here are some useful Javascript snips for working with form data.
How to get the name of the HTML tag for an element:
[code]this.nodeName.toLowerCase()[/code]
This code will see if we have a map set of inputs (somename[]):
[code]// See if we have a map here
var mapFound = 0;
if (thisName.indexOf(‘[]’) != -1) {
mapFound = 1;
thisName = thisName.replace(/[\[\]’]+/g, ”);
}[/code]
How to take a map of inputs and turn them into a Javascript map type var, and toss the empty ones:
[code]var map = $(thisName).map(function(){
if (this.value != ”) {
return this.value;
} else {
return null;
}
}).get();[/code]
Tags: form, html, javascript, jquery, programming
Posted in Code | No Comments »