메뉴 건너뛰기

조회 수 1125 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

jquery의 attr()과 removeAttr()이라는 메소드는 해당 객체의 속성을 넣었다 뺐다 할 수 있다.
그리고 예를 들어 보였던 객체를 안보기에 하려고 한다면, 아래와 같이 하면 된다.(사실 보이는 객체를 안보이게 하려면 toggle()을 쓰면 간단하지만..... )

if( a == 1 ) $('id').attr('style', "display:inline;");
else  $('id').attr('style', "display:none;");


단순히 해당 속성의 값을 재설정 해주면 되는것이다.
그런데, 이런 간단한 경우 말고, 해당 속성의 같은이름을 가지는 여러값을 한번에 바꿔준다거나, 할때도 있을것이다. 예를 들어 width, height 가 모두 100px인데 이걸 모두 200px로 바꿔 주고 싶다거나 할 때 말이다.
이럴때는 아래와 같이 하면 된다.

<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>

<script type="text/javascript">
$( function() {
  $('#bt').click( function(){
    if( $(this).val() == "click!!" )
    {
      $('#bt').attr('style', $('#bt').attr('style').split('50px').join('100px'));
      $(this).val("click!");
    }
    else
    {
      $('#bt').attr('style', $('#bt').attr('style').split('100px').join('50px'));
      $(this).val("click!!");
    }
  });
});
</script>

<input type="button" id="bt" value="click!!" style="height:50px;width:50px;">
 


그냥 attr()을 이용해서 비슷한 값을 모두 replace시키는 것이라고 생각하면 된다. 직접 돌려보면 어떤식으로 되는지 알수 있을것이다. 응용은 알아서 하길 바란다.


  1. 행에 징검다리 스타일 입히기 (:odd, :even)

    Date2021.03.31 Views210
    Read More
  2. 제이쿼리에서 클래스(class) 이름 추가/삭제

    Date2021.03.31 Views233
    Read More
  3. click event scroll

    Date2021.03.31 Views827
    Read More
  4. click에 따른 마우스 휠 on off

    Date2021.03.31 Views299
    Read More
  5. 다중 select

    Date2021.03.31 Views316
    Read More
  6. draggable - div 드래그

    Date2021.03.31 Views271
    Read More
  7. parent of the iframe element selector

    Date2021.03.31 Views205
    Read More
  8. prepend / append - element 추가 (부모/자식 관계)

    Date2021.03.31 Views225
    Read More
  9. before / after / insertBefore / insertAfter - element 추가 (동등 관계)

    Date2021.03.31 Views168
    Read More
  10. 마우스 좌표 얻기

    Date2021.03.31 Views271
    Read More
  11. 간단한 마우스 포인터 따라 다니기

    Date2021.03.26 Views594
    Read More
  12. change 전의 값을 가져오기

    Date2021.03.26 Views246
    Read More
  13. focus() 로 오브젝트 옮기기

    Date2021.03.26 Views171
    Read More
  14. 새창(자식창) 제어하기, 새창 POST방식으로 값 넘기기

    Date2021.03.26 Views785
    Read More
  15. SELECTBOX MULTIPLE 검색하기

    Date2021.03.26 Views568
    Read More
  16. easing - 효과의 진행 속도

    Date2021.03.26 Views156
    Read More
  17. fadeIn() , fadeOut() 을 이용한 간단한 자동 그림 전환

    Date2021.03.26 Views285
    Read More
  18. 정규식, 한글 못쓰게 하기, replace all

    Date2021.03.26 Views842
    Read More
  19. input checkbox 모두 체크하기

    Date2021.03.26 Views176
    Read More
  20. attr() - style의 특정 속성만 바꾸기

    Date2021.03.26 Views1125
    Read More
Board Pagination Prev 1 2 3 4 5 6 7 8 9 Next
/ 9

하단 정보를 입력할 수 있습니다

© k2s0o1d4e0s2i1g5n. All Rights Reserved