I just recently started with Javascript and jQuery. My background is in Python. I would be more than happy to get some feedback if this coding style of mine is optimal, or if in JS people generally write things differently.
The current task is to build different elements in a website that are always hosted in the same container. I have written a container creation function like this:
function create_container(type, counter) {
var ret = $('<div />').attr({
class: 'container-box',
}).data({
type: type,
counter: counter,
}).append(
$('<span />').attr({
class: 'remove'
}).append('×')
);
return ret
}
var b = create_container('text', 0);
console.log(create_container('text', 0));
This function will then be reused in different objects to create the same containing container. Type and counter will be set when the object will be initiated.