본문 바로가기

web/jQuery

jQuery prev() next()

<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
 <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
    <script type="text/javascript">
    
     $(function()
  {
        testprev();
  testnext();
  });
  
  function testprev(){
$('button#first').prev().text('버튼 앞에 붙어요!');
}
function testnext(){
$('button.third').next().text('버튼 뒤에 붙어요!');
}
    </script>
</head>
<body>

<div>
<span></span>
<button id="first">First</button>
<span></span>
</div>
<div>
<span></span>
<button>Second</button>
<span></span>
</div>
<div>
<span></span>
<button class="third">Third</button>
<span></span>
</div>

</body>
</html>




prev()는 선택된 엘리먼트의 앞에 next()는 엘리먼트의 뒤를 뜻한다.

'web > jQuery' 카테고리의 다른 글

jQuery after() prepend()  (0) 2011.01.11
jQuery click()  (0) 2011.01.10
jQuery val() 두번째  (0) 2011.01.09
jQuery val()  (0) 2011.01.08
jQuery insertAfter()  (0) 2011.01.06