Multiple "properties" in jQuery
Just a fast and simple question: how do I add multiple classes to the same element? I got this code and I want to be able to apply class1
, class2
, class3
to this function. The markerClasses are different marks on a map and I want to be able to choose which mark I want to use on my page (开发者_运维技巧class1
, class2
...).
$(function(){
$('.map').mobilymap({
markerClass: 'class1'
});
});
I thought it would be something like markerClass: 'class1 class2'
or markerClass: '.class1 .class2'
but it won't work. Thanks in advance!
The module seems to not support multiple classes by default, but the current version should work if you do something like that:
$(function(){
$('.map').mobilymap({
markerClass: 'class1, .class2, .class3'
});
});
(I know, it looks strange, but the module was not developed to support that at the moment)
Please test it and tell me if it worked correctly. It should treat all the elements with classes class1
, class2
and class3
equally, as if they have one class specified by markerClass
setting.
It's not working because they aren't actually setting the class in their code. They are also only looking for a single class.
point = $this.find("." + sets.markerClass)
and here
div = content.find("." + sets.markerClass).filter(function() {
return $(this).attr("id") == rel
});
Don't mind this plugin limitations and add your owns classes after your mobilymap thingy:
$(function(){
$('.map').mobilymap({
markerClass: 'marker'
});
$('.marker').addClass('class1 class2 class3');
});
精彩评论