/domexamples.html Secret
Created
March 5, 2016 11:06
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!document html> | |
<html> | |
<head> | |
<meta charset="utf-8" /> | |
<script src="https://code.jquery.com/jquery-2.2.1.min.js"></script> | |
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script> | |
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"> | |
</head> | |
<body> | |
<div class="container"> | |
<div class="row"> | |
<div class="col-lg-6" id="outputPlain">Tutaj będzie widać wartość która ustawisz w data</div> | |
<div class="col-lg-6" id="outputData">Do tego elementu będę wypisaywać wartość odczytaną z data</div> | |
</div> | |
<div class="row"> | |
<input id="inputSource" type="text" name="textInput"/> | |
</div> | |
<div class="row"> | |
<button id="writeData">Zapisz z jQuery data</button> | |
<button id="writeAttr">Zapisz z jQuery attr</button> | |
<button id="writeJS">Zapisz z setAttribute</button> | |
<button id="readData">Czytaj z jQuery data</button> | |
<button id="readAttr">Czytaj z jQuery attr</button> | |
<button id="readJS">Czytaj z setAttribute</button> | |
</div> | |
</div> | |
<script type="text/javascript"> | |
var onWriteDataClick=function(){ | |
var text = $("#inputSource").val(); | |
$("#outputPlain").text(text); | |
$("#outputData").data("blog-example", text); | |
}; | |
var onWriteAttrClick=function(){ | |
var text = $("#inputSource").val(); | |
$("#outputPlain").text(text); | |
$("#outputData").attr("data-blog-example", text); | |
}; | |
var onWriteJSClick=function(){ | |
var text = $("#inputSource").val(); | |
$("#outputPlain").text(text); | |
document.getElementById("outputData").setAttribute("data-blog-example", text); | |
}; | |
var onReadDataClick=function(){ | |
var text = $("#outputData").data("blog-example"); | |
$("#outputData").text(text); | |
}; | |
var onReadAttrClick=function(){ | |
var text = $("#outputData").attr("data-blog-example"); | |
$("#outputData").text(text); | |
}; | |
var onReadJSClick=function(){ | |
var text = document.getElementById("outputData").getAttribute("data-blog-example"); | |
$("#outputData").text(text); | |
}; | |
$("#writeData").on("click", onWriteDataClick); | |
$("#writeAttr").on("click", onWriteAttrClick); | |
$("#writeJS").on("click", onWriteJSClick); | |
$("#readData").on("click", onReadDataClick); | |
$("#readAttr").on("click", onReadAttrClick); | |
$("#readJS").on("click", onReadJSClick); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment