ProgramingTip

div 클래스의 스타일 속성을 변경하는 jquery

bestdevel 2020. 10. 25. 12:43
반응형

div 클래스의 스타일 속성을 변경하는 jquery


이와 같은 클래스 클래스가 언어 스타일 속성 style = "left : 336px" 를 변경하고 싶습니다.

<div id="range-cont">
<div class="slider">
<div class="progress" style="width: 350px;"></div>
    <a class="handle" href="#" **style="left: 336px;"**></a>
</div>
<input id="percentage" class="range" type="range" value="14" name="percentage" min="0" max="100">
<p id="percent-label">%</p>
</div>
</div>

시도 $('.handle').css({'style':'left: 300px'})했지만 작동하지 않습니다. 내가 여기서 뭘 잘못하고 있는지 모르겠다.


단지 시도 $('.handle').css('left', '300px');


스타일 속성을 설정 비용

$('.handle').attr('style','left: 300px');

또는 jQuery의 CSS 방법을 사용하여 하나의 CSS 스타일 속성 만 접근 할 수 있습니다.

$('.handle').css('left', '300px');

또는 키 값과 동일

$('.handle').css({'left': '300px', position});

W3schools에 대한 추가 정보


시도

$('.handle').css({'left': '300px'});

대신에

$('.handle').css({'style':'left: 300px'})

$('.handle').css('left', '300px');

$('.handle').css({
    left : '300px'
});

$('.handle').attr('style', 'left : 300px');

또는 OrnaJS 사용


$('.handle').css('left','300px') 시도해 사용, 식별자 먼저 다음 값

여기에 대한 자세한 내용 :

http://api.jquery.com/css/


이게 도움이 되요 ..

$('.handle').css('left', '300px');

스타일은 속성 css작동하지 않습니다.attr

변화 :

$('.handle').css({'style':'left: 300px'});

T0 :

$('.handle').attr('style','left: 300px');//Use `,` Comma instead of `:` colon

$('#Id').attr('style',' color:red');$('#Id').css('padding-left','20%');
동시에 사용할 수 없습니다 .
당신도 사용할 수 있습니다 attr 또는 css 그러나이 단독으로 사용하는 경우 모두에만 작동합니다.

참고 URL : https://stackoverflow.com/questions/19581763/jquery-to-change-style-attribute-of-a-div-class

반응형