본문 바로가기
개발/jquery

2010-12-26

by rudnine 2010. 12. 26.
반응형
// 페이지의 모든 div를 숨긴다.
jQuery('div').hide();

// 모든 div의 내부 텍스트를 변경한다.
jQuery('div').text('new content');

// div에 updatedContent 클래스를 추가한다.
jQuery('div').addClass("updatedContent");

// 페이지에 모든 div를 나타낸다.
jQuery('div').show();

--> 이는 체인을 사용하여 다음과 같이 변경가능
jQuery('div').hide().text('new content').addClass("updatedContent").show();

--> 들여쓰기와 줄바꿈을 사용하여 다음과 같이 변경가능
jQuery('div')
.hide()
.text('new content')
.addClass("updatedContent")
.show();


=====================================================================================

<script type="text/javascript">
jQuery(document).ready(function(){
alert(jQuery('p').text());
});
</script>

-----------------------------------------

<p class="intro">test </p>
<h2>This is a heading</h2>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p><button type="button">Click me</button>



위의 예제코드 속도를 올리기 위해서는
- 자바스크립트 코드를 코드 하단에 둔다. (단, /body 위에 존재해야 함)
- ready()를 사용하지 않는다.

아래와 같이 코딩한다.

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>eventDiary</title>
</head>
 
<body>

<p>The DOM is ready!</p>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>

<script type="text/javascript">
jQuery(document).ready(function(){
alert(jQuery('p').text());
});
</script>
</body>
</html>

------------------------------ jQuery Cookbook 1.3절까지 실습.

반응형

'개발 > jquery' 카테고리의 다른 글

jQuery 관련링크모음  (0) 2010.12.30
2010-12-28  (0) 2010.12.29
2010-12-25  (0) 2010.12.25
jQuery Attribute Selectors  (0) 2010.12.22
jquery 1  (0) 2010.12.20

댓글