programing

jQuery의 removeAttr로 여러 특성 제거

minimums 2023. 11. 4. 10:32
반응형

jQuery의 removeAttr로 여러 특성 제거

저는 다음과 같은 코드를 가지고 있습니다.

$(document).ready(function(){
 $('#listing img')
 .attr('width', 250)
 .removeAttr('height').removeAttr('align').removeAttr('style')
 .wrap('<p />');
});

다중 속성을 제거하는 보다 효율적인 방법이 있습니까?

예:

.removeAttr('height align style')

설명서에서:

버전 1.7에서는 공백으로 구분된 속성 목록이 될 수 있습니다.

예, 다음과 같은 방법으로 제거할 수 있습니다.

$('#listing img').removeAttr('height align style');

다음과 같은 특성을 추가할 수도 있습니다.

$('#listing img').attr({ height: "20", align: left }).css({ color: red, text-align: center });

언급URL : https://stackoverflow.com/questions/13725301/remove-multiple-attributes-with-jquerys-removeattr

반응형