This But Not $(this)
OK so in jQuery; I have a selecter $('#gmap') I want to do alot of code in context of my selector. I have always been lazy and used .each() even though there is only one of them.
Solution 1:
well if there is only one one them (should be because you are selecting by id) you can just chain methods $("#gmap").val("new").attr('someattr','')
.etc
Solution 2:
Just cache the object and work with it like normal:
var$gmap = $('#gmap321654987789'); // Get your jQuery object
console.log($gmap);
console.log($gmap.text());
Solution 3:
Solution 4:
You can also try "with" in JS so you focus on the properties of your object.
Solution 5:
try this (untested)
(function($){
$.fn.me = function(func) {
func.call(this[0]);
returnthis;
}
})(jQuery);
and use with:
$("#gmap321654987789").me(function(){
this.innerHTML = 'edited';
}).css('border')....
Post a Comment for "This But Not $(this)"