开发者

jquery attr.() only working in firefox?

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜