2017-05-30 21 views
0

要素の幅を:afterで動的に変更しようとしています。しかし、それは反映されていません。助けてもらえますか?ここで JQueryからの擬似CSS要素の後ろの幅を変更します。

$(function(){ 
 
var a=20; 
 
$(".progress:after").width(a+"%"); 
 
// This is not showing 20%. Still shows 50% which was coded in CSS 
 
});
.progress { 
 
    width:200px; 
 
    height:50px; 
 
    border:1px solid black; 
 
    position:relative; 
 
} 
 
.progress:after { 
 
    content:'\A'; 
 
    position:absolute; 
 
    background:black; 
 
    top:0; bottom:0; 
 
    left:0; 
 
    width:50%; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<div class="progress"></div>
はJSFidle

+1

あなたは '$( "進歩。:後")を使用することはできません'セレクタとして。 – Twisty

+0

質問..偽の目的は何ですか?動的なコンテンツがありますか? – Cam

+0

見てくださいhttps://stackoverflow.com/questions/29260296/modify-pseudo-select-after-in-javascript – HTCom

答えて

1

Linkであるあなたが使用する必要があり、利用可能になりまし、HTML5 progress element

$(function() { 
 
    var a = 20; 
 
    $("progress").prop('value', a); 
 
});
progress { 
 
    width:200px; 
 
    height:50px; 
 
    border:1px solid black; 
 
    position:relative; 
 
    background:transparent; 
 
} 
 
::-webkit-progress-bar{background:transparent;} 
 

 
::-moz-progress-bar{background-color:black;} 
 
::-ms-fill{background-color:black;} 
 
::-webkit-progress-value{background-color:black;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<progress value="50" max="100"></progress>

関連する問題