Reputation: 37
I want to change style with jquery like this:
$(document).ready(function(){
$('#tmadrp').click(function(){
if($('#tmadrp option:selected').val().toString()=='theme1')
{
$('link[href="style1"]').remove();
$('head').append('<link type="text/css" href="syle2"/>')
}
});
but this doesnt react.How can I do. thanks.
Upvotes: 0
Views: 53
Reputation: 318172
A more proper way to do this would be:
$(document).ready(function(){
$('#tmadrp').on('click', function(){
if ($.trim( this.value ) == 'theme1' ) {
$('link[href="style1"]')[0].disabled = true;
var link = $('<link />', {type: 'text/css', href: 'syle2'});
$('head').append(link);
}
});
});
You do know you've written 'syle2' and not 'style2', and that removing a stylesheet does'nt remove the styles as they are already loaded ?
Upvotes: 1