Skip to content

Commit f4c86c5

Browse files
authored
Update README.md
1 parent 88490a3 commit f4c86c5

File tree

1 file changed

+100
-0
lines changed

1 file changed

+100
-0
lines changed

README.md

+100
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,106 @@ val=document.getElementsByTagName('li');//bütün li etiketlerini aldı
300300
val = document.querySelectorAll('li');//burdada li yi verir fakat Nodelist olrak
301301
//buda bize forEach gibi yapıları kullanmamıza yarar
302302

303+
```
304+
### Dom elementleri üzerinde oynama
305+
306+
```jsx
307+
let val; //class
308+
let list = document.querySelector('.list-group');
309+
val = list;
310+
val = list.childNodes; //Nodelist leri bize gösterir
311+
val = list.childNodes[0]; //0 ıncı nodelist i getirir
312+
val = childNodes[0].nodeType; //node un tipini gösterir 3 gibi
313+
val = list.children[0]; //ilk list-group etiketli li yi gösterir
314+
val = list.children[2].textContent='new item';// textini new item yapar 3. list i
315+
val = list.firstElementChild;//ilk eleman gelir
316+
val = lastElementChild; //son elemanı alır
317+
318+
for(let i=0; i<list.children.length; i++){ //list-group un length i kadar
319+
if(list.childNodes[i].nodeType===1){
320+
console.log(list.childNodes[i]);
321+
}
322+
}
323+
```
324+
325+
### Element oluşturma
326+
327+
```jsx
328+
//create element
329+
const li = document.createElement('li'); //bir li etiketi oluşturduk
330+
console.log(li)
331+
//add class
332+
li.className='list-group';
333+
//add attribute
334+
li.setAttribute('title','new item');
335+
li.setAttribute('placeholder','sayı giriniz');
336+
//text node
337+
const text = document.createTextNode('new item');
338+
li.appendChild(text); //new item text bölümüne eklendi
339+
//add link
340+
const a = document.createElement('a');
341+
a.setAttribute('href','#');
342+
a.className='list-item';
343+
```
344+
345+
### element silme
346+
347+
```jsx
348+
const tasklist = document.querySelector('#task-list');
349+
tasklist.remove(); //ul listesi silindi
350+
//belli bir eleman silme
351+
tasklist.childNodes[7].remove(); //8. elemanı sildik
352+
//diğer yolr
353+
tasklist.children[0].remove(); //1. elemanı sildi
354+
//removing attribute
355+
tasklist.children[0].removeAttribute('class');
356+
//örnek
357+
for(let i=0;i<tasklist.children.length;i++){
358+
tasklist.children[i].removeAttribute('class');
359+
}
360+
```
361+
362+
## javascript - events
363+
364+
```jsx
365+
const button = document.querySelector('#btnDeleteAll');
366+
btn.addEventListener('click',function(){
367+
console.log('button clicked');
368+
});
369+
//diğer kullanımı
370+
btn.addEventListener('click',btnClick);
371+
372+
function btnClick(){
373+
console.log('clicked');
374+
}
375+
//link
376+
btn.addEventListener('click',function(e){
377+
console.log('clicked')
378+
e.preventDefault(); //böylece linkin görevibi yapması yerine clicked yazdı
379+
});
380+
381+
```
382+
383+
### mouse events
384+
385+
```jsx
386+
const btn = document.querySelector('#btnDeleteAll')
387+
const ul = document.querySelector('#task-list');
388+
//click
389+
btn.addEventListener('click',eventHandler);
390+
391+
function. eventHandler(event){
392+
console.log(`event type: ${event.type} `);
393+
}
394+
//çıktı: event type: click
395+
396+
//double click
397+
btn.addEventListener('dbclick',eventHandler);
398+
399+
function eventHandler(event){
400+
console.log(`event type: ${event.type}`);
401+
}
402+
//çıktı: event type: dbclick
303403
```
304404

305405
## Javascript kullanıcıya girdi sormak

0 commit comments

Comments
 (0)