JQuery Seçiciler

JQuery tarafında seçiciler dediğimizde obje, stil dosyaları ve HTML tag’lerinin seçilmesinin sağlanması anlamına gelir. 

ID Bazlı Nesne Seçmek :

JQuery tarafında HTML’ de ID verilip bir nesneyi aşağıdaki şekilde seçebilirsiniz;

<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    $("#test").hide();
  });
});
</script>
</head>
<body>
 
<h2>This is a heading</h2>
<p>This is a paragraph.</p>
<p id="test">This is another paragraph.</p>
<button>Click me</button>
 
</body>
</html>

Stil Bazlı Nesne Seçmek :

JQuery ile belli stil tanımlamalarına göre belli işlemler yaptırmak için seçim yapılabilir. Örnek olarak aşağıdaki koda bakılabilir;

<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    $(".test").hide();
  });
});
</script>
</head>
<body>
 
<h2 class="test">This is a heading</h2>
<p class="test">This is a paragraph.</p>
<p>This is another paragraph.</p>
<button>Click me</button>
 
</body>
</html>

HTML Bazlı Nesne Seçmek :

<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    $("p").hide();
  });
});
</script>
</head>
<body>
 
<h2>This is a heading</h2>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<button>Click me</button>
 
</body>
</html>

this ile Nesne Seçimi :

JQuery ile this tanımı çağrıldığı fonksiyona ait olan obje anlamına gelir ve o objenin ID yada NAME değerini yazmadan direkt ulaşımı sağlar. Aşağıdaki örnek baz alınabilir;

<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    $(this).hide();
  });
});
</script>
</head>
<body>
 
<h2>This is a heading</h2>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<button>Click me</button>
 
</body>
</html>

NAME Bazlı Nesne Seçimi :

JQuery nesneleri ID bazlı seçim dışında ID’lere verilen isim(name) bazlı da seçim yapabilir. Fakat bunu doğru bir şekilde gerçekleştirebilmesi için nesnelerin tiplerinin belirtilmesine ihtiyaç duyar. Aşağıdaki örneği bir inceleyelim;

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>attributeEndsWith demo</title>
  <script src="//code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
  
<input name="newsletter">
<input name="milkman">
<input name="jobletter">
  
<script>
$( "input[name='newsletter']" ).val( "a letter" );
</script>
  
</body>
</html>
Etiket(ler): , , , .Yer işareti koy Kalıcı Bağlantı.

Bir yanıt yazın

E-posta adresiniz yayınlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir