次のコードは機能しますか?
var htmlattri="background-color:red;";
$('a').css("style",htmlattri);
そうでない場合、正しい解決策は何ですか?
あなたはほとんどそこにいました。パラメータ名と値を別々に指定する必要があります。$('a').css("background-color","red");
これを使って
$('a').css('background-color','red');
または、このタイプも使用できます
$('a').css({background-color:'red'});
次のコードを試してください。
$('a').css('background-color','red');
$('a').css('backgroundColor': 'red');