I have a tag with different options, if you choose an option it is supposed to 开发者_开发问答change the font-family of an inputfield. This works great in firefox but not responding in either IE or Chrome. This is how my option looks like
<option onclick="$('#blogEntrySubject').attr('style', 'font-family:Arial;');">My option</option>
Is this wrong?
I suppose one could say that is wrong, yes. Use the css(propertyName, value)
method to manipulate the applied styles directly:
$('#blogEntrySubject').css("font-family", "arial");
Also, as noted in comments by now: beware stray quotes.
should be
$('#blogEntrySubject').css('fontFamily', 'Arial');
This is the solution:
<option>
Does not have an onclick event by default in other browsers than Firefox. So what you have to do is adding an onchange event to the <select>
tag. So for me to change the font I set my option like this:
<option value="Arial">Arial</a>
And my select looks something like this:
<select onchange="$('#blogEntrySubject').css('font-family', this.value);">
This works in all broswers. Thank you all for your input.
精彩评论