I want to write a new version of my jQuery extension but I want to ask before diving into it. So here is what I have and what I want, I am not sure whether I am goind in the good way with this question so feel free to express your opinions. =)
Dynamic element creatin with jQuery - I have always been kinda 'lazy' with
$(selector).html("<h2>I rule!</h2>");
so I wanted something else and here I go:
var div = $("body > .wrapper > div.my-class[data-help=custom help message]").mk();
So actually what this extension does is that it creates a 'div' element with attributes of class and data-help and appends it to 'body > .wrapper' (the last '>' is the indicator where to apend it) immediately, and finally returns the 'div'.
So as you can see, this is more like a 'descriptor' than a selector. Fine, but...
What I want to achieve is this: When I am calling $(), I want to write a code which makes a decision first before letting jQuery does its job. So this is what I thought of it could look like:
//this doesn't append to any element,
//only returns a new 'div' element
var div = $("make:div.my-class[data-help=custom help message]");
As you can see I would like to 'prepocess' the selector before it gets digested by jQuery. I want to check whether the selector contains
if ((/^make\:/i).test(selector)) { ... }
and if it does, I want to call my extension with selector.subsrting(5).
So basically I want to push a command inside the selector and execute my extension before letting jQuery do its job.
So is there any way achieving the desired result?
Anyways, it is a nice experiment for me... =)
Thanks in advance! =)