<html>
<head>
<script src="https://code.jquery.com/jquery-2.1.4.js"></script>
<meta charset="utf-8">
<title>Ukázka selektorů v jQuery</title>
<link rel="stylesheet" href="http://yui.yahooapis.com/pure/0.6.0/pure-min.css">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<h1 class="nadpis">Ukázky použití selektorů v jQuery</h1>
<h2 class="nadpis">CSS selektory</h2>
<div class="ukazka ukazka-1">
<input type="button" id="ukazka1a" value="Změnit barvu nadpisů">
<input type="button" id="ukazka1b" value="Změnit barvu H1">
<input type="button" id="ukazka1c" value="Změnit barvu H2">
<input type="button" id="ukazka1d" value="Přepnout první tlačítko">
</div>
<h2 class="nadpis">Atributové selektory</h2>
<div class="ukazka ukazka-2">
<input type="text" name="ukazka-jedna" placeholder="Text 1">
<input type="text" name="ukazka-dva" placeholder="Text 2">
<input type="button" id="ukazka2a" value="Přepnout políčka">
<input type="button" id="ukazka2b" value="Přepnout Text 2">
<input type="button" id="ukazka2c" value="Nadpisy o selektorech">
</div>
<h2 class="nadpis">Pořaďové selektory</h2>
<div class="ukazka ukazka-3">
<input type="button" id="ukazka3a" value="Obarvit 3. a další H2">
<input type="button" id="ukazka3b" value="Obarvit první dva nadpisy">
</div>
<h2 class="nadpis">Použití each() a $(this)</h2>
<div class="ukazka ukazka-4">
<input type="button" id="ukazka4" value="Vylepšit tlačítka">
</div>
<h2 class="nadpis">Operátory u selektorů</h2>
<div class="ukazka ukazka-5">
<input type="button" id="ukazka5a" value="Operátor začíná">
<input type="button" id="ukazka5b" value="Operátor obsahuje">
</div>
</body>
</html>
.cervene{ color: red; }
.modre{ color: blue; }
.zelene{ color: green; }
.zlute{ color: yellow; }
$(document).ready(function(){
// CSS selektory
$('#ukazka1a').click(function(){
$('.nadpis').toggleClass('cervene');
});
$('#ukazka1b').click(function(){
$('h1').toggleClass('modre');
});
$('#ukazka1c').click(function(){
$('h2.nadpis').toggleClass('zelene');
});
$('#ukazka1d').click(function(){
$('#ukazka1a').toggle();
});
// atributové selektory
$('#ukazka2a').click(function(){
$('input[type="text"]').toggle();
});
$('#ukazka2b').click(function(){
$('input[name="ukazka-dva"]').toggle();
});
$('#ukazka2c').click(function(){
$('.nadpis:contains("selektor")').toggleClass('cervene');
});
// pořaďové selektory
$('#ukazka3a').click(function(){
$('h2:gt(1)').toggleClass('zlute');
});
$('#ukazka3b').click(function(){
$('.nadpis:lt(2)').toggleClass('zlute');
});
// each() a $(this)
$('#ukazka4').click(function(){
$('input').each(function(){
if ($(this).attr('type') == 'button'){
$(this).addClass('pure-button');
}
});
});
// operátory u selektorů
$('#ukazka5a').click(function(){
$('input[id^="ukazka1"]').toggleClass('pure-button-primary');
});
$('#ukazka5b').click(function(){
$('input[id*="2a"]').toggleClass('pure-button-primary');
});
});
Output
You can jump to the latest bin by adding /latest
to your URL
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |