Reputation: 8487
I am trying to change the class os an element which is icon-local
to icon-local-img
by adding the -img
to the end of the class.
Here is what I am trying. Why is it not working?
HTML
<div class="icon-local">sdvdfvsdfvdfs fdsfggfd</div>
CSS
.icon-local {
color:#00f;
}
.icon-local-img {
color:#f00;
}
JS
$(document).ready(function () {
function swapClass($obj) {
$($obj).toggleClass($obj + ' ' + $obj + '-img');
}
if (!$('html').hasClass('fontface')) {
swapClass('icon-local');
swapClass('icon-mail');
swapClass('icon-phone');
}
});
Upvotes: 0
Views: 33
Reputation: 57105
function swapClass($obj) {
$('.' + $obj).toggleClass($obj + ' ' + $obj + '-img');
//^ class selector
}
Upvotes: 2