[Day3] jQuery 3 [12/1] 

 

jq DOM μ‘°μž‘

        μš”μ†Œ μ‰½κ²Œ μ—‘μ„ΈμŠ€, μ‘°μž‘(생성, μˆ˜μ •, μ‚­μ œ, 이동 λ“±λ“±)  - DOM κ΄€λ ¨ λ©”μ„œλ“œ 

        DOM - html, xml λ¬Έμ„œμ— μ—‘μ„ΈμŠ€ ν•˜κΈ° μœ„ν•œ ν‘œμ€€ μ •μ˜

        

        1) jq DOM method : 

           val()        input value     μ„€μ •, λ°˜ν™˜                             value

           text()      <μ‹œ>ν…μŠ€νŠΈ</μ’…>  html  X  μ„€μ •, λ°˜ν™˜            innerText

           html()     <μ‹œ>ν…μŠ€νŠΈ</μ’…>  html O  μ„€μ •, λ°˜ν™˜             innerHTML

           

        2) 속성 λ°˜ν™˜, μ„€μ •

            attr()

            prop()

            is()

  <input type="text" id="name" value="<b>admin</b>">
  <br>
  <button>확인</button>
  <p id="demo"></p>
  
  <hr>
  <!-- http://www.sist.co.kr -->
  <a href="#">sist</a>
<script>
  // $(document).ready(function (){});
  $(function (){
	  // $("a").href
	  // $("a").prop("href", ??)
	  
	  
	  // $("a").attr("href", "http://www.sist.co.kr");
	  
	  // href  속성 μ„€μ • + alt  속성
	  $("a").attr({
		  "href":"http://www.sist.co.kr",
		  "alt":"test",
		  "title": "μŒμš©κ΅μœ‘μ„Όν„°"
	  });
	  
  });
</script>  
  
<script>
   // js
   /*
   document.querySelector("button").onclick = function (){
	   //document.getElementById("demo").innerText
	   document.getElementById("demo").innerHTML
	        =  document.getElementById("name").value;
   }
   */
</script>
<script>
    // jq 
    // $(selector).action();
    $("button").click( function (){
    	// $("#demo").text(  $("#name").val() );
    	// $("#demo").html(  $("#name").val() );
    	
    	$("#name").val( "xxx" );
    });
    
</script>

 


  [ jq μš”μ†Œ μΆ”κ°€ ]                     ex03_02.html

    append() / appendTo()    λΆ€λͺ¨.append(μžμ‹) , μžμ‹.appendTo(λΆ€λͺ¨)

    prepend() / prependTo()

    before()

    after()

    

     [ jq μš”μ†Œ μΆ”κ°€ ] 

     remove()       μ„ νƒν•œ μš”μ†Œλ₯Ό  제거

     empty()         μ„ νƒν•œ μš”μ†Œμ˜  μžμ‹ μš”μ†Œλ₯Ό 제거

    

    

    [ js μš”μ†Œ μΆ”κ°€ ]

    var p = document.createElement("p");

    appendChild( p )

    removeChild( p );

    p.remove();    

    insertBofore()


  [jq CSS μ‘°μž‘]

  1.  css()

  2. addClass()

  3. removeClass()

  4. toggleClass()

  5. hasClass()  true/fasle


  [jq  μš”μ†Œ, μœˆλ„μš°  크기]

  1.                              width()

  2. height()

  3.                              innerWidth()

  4. innerHeight()

  5.                               outerWidth()

  6. outerHeight()

  

    [λ„ˆλΉ„(width)]

    

                                  margin  border  padding        [content]          padding      border     margin

                                    10px     2px         5px                                        5px           2px         10px

       

         jq  width()                                                |<-                        ->|    

         jq innerWidth()                        |<-                                                         ->|    

         jq outerWidth()            |<-                                                                                       ->|    

jq outerWidth(true)  |<-     


  jq  탐색(Traversing(νš‘λ‹¨))

    -  증쑰뢀λͺ¨

          γ„΄ μ‘°λΆ€λͺ¨

                  γ„΄ λΆ€λͺ¨

                        γ„΄ μžμ‹, +  μžμ‹ ... ( ν˜•μ œ )

                            γ„΄ μ¦μ†μž + μ¦μ†μž ..

                            

    [ λΆ€λͺ¨ νƒμƒ‰ν•˜λŠ” jq λ©”μ„œλ“œ ]                         

    parent()

    parents()

    parentsUntil()     

 

jquery 탐색( μžμ† )

    - children()  : μ„ νƒν•œ μš”μ†Œμ˜ λͺ¨λ“  직계 μžμ‹μ„ λ°˜ν™˜

    - find()        : μ„ νƒν•œ μš”μ†Œμ˜      λͺ¨λ“  ν•˜μœ„(후손)을 λ°˜ν™˜

 

   1. 쑰상 탐색

       parent(), parents(), parentsUntil()

   2. 후손 탐색

       children(), find()

   3. ν˜•μ œ 탐색

      siblings()      

      next()  / prev()      

      nextAll(), nextUntil()

      prevAll(), prevUntil()

  4. 필터링

      first()

      last()

      not()

      eq()

      

      filter()


  jQuery ν”„λ ˆμž„μ›Œν¬  μ‚¬μš© + λ‹€λ₯Έ ν”„λ ˆμž„μ›Œν¬ ν•¨κ»˜ μ‚¬μš©.

   $ 기호                                    $ 기호                            [ 좩돌 ]

   jQuery("p")

   μž‘λ™ X

   

   => jquery method :   noConflict() λ©”μ„œλ“œλ₯Ό μ‚¬μš©ν•΄μ„œ 좩돌 ν•΄κ²°..


     // js     κ°μ²΄μƒμ„±μž - 객체λ₯Ό 생성할 λ•Œ μ‚¬μš©λ˜λŠ” ν•¨μˆ˜   , λŒ€λ¬Έμžλ‘œ ν•¨μˆ˜λͺ… μ‹œμž‘.

     // days08 폴더  jquery-3.6.1.js       164 라인

     

     jQuery.fn = jQuery.prototype = {

 

// The current version of jQuery being used

jquery: version,

 

constructor: jQuery,

    :

}

 

// 객체 μƒμ„±μžλ‘œ 속성, λ©”μ„œλ“œ μΆ”κ°€

//  Person.prototype.속성λͺ…

//  Person.prototype.λ©”μ„œλ“œλͺ… = function (){}


    wrap()                      / unwrap()

    감싸닀(포μž₯ν•˜λ‹€)


    [ jq  이벀트 등둝 ]

    on()            jquery Ajax ( κΈ°μ–΅ )

    one()          이벀트 ν•œλ²ˆλ§Œ 등둝.

    off() 


        each()  검색

        1)  μ»¬λ ‰μ…˜ μ‘°μž‘ :  each()

        2) μœ ν‹Έλ¦¬ν‹°      :  jQuery.each()

  • 넀이버 λΈ”λŸ¬κ·Έ κ³΅μœ ν•˜κΈ°
  • 넀이버 λ°΄λ“œμ— κ³΅μœ ν•˜κΈ°
  • 페이슀뢁 κ³΅μœ ν•˜κΈ°
  • μΉ΄μΉ΄μ˜€μŠ€ν† λ¦¬ κ³΅μœ ν•˜κΈ°