What you are really missing is a nice formatting method for javascript so what you're trying to do isn't drowned out by all your quotes.
I like the format method referenced here. Here it is reproduced as a utility function so you don't have to monkey patch the built-in string object.
var format = function(target) {
var args = arguments;
return target.replace(/{(\d+)}/g, function(match, number) {
number = parseInt(number) + 1;
return typeof args[number] != 'undefined'
? args[number]
: match
;
});
};
Then you could do:
var selector = format(".hierarchical[data-dependson='{0}']", id);
// or with the monkey patch
selector = ".hierarchical[data-dependson='{0}']".format(id);
$(selector)
Still a little messy, but fundamentally you're splicing a value into a string. I also in no way vouch for the performance of any of this. Other answers probably make a good point that this is slow, but that's not your question.