So here is the usual html file uploading interface
I wanted to show a button to choose file and After choosing display a button to upload that file. Chosen file name also displayed in a nice way. As follows
document.getElementById("GetViewsbyPageId").onchange = function () {
var pageId = $("#GetViewsbyPageId").val();
if (pageId != 0) {
$("#LoadViewsbyPageId").show();
//sending a get request
$.get('page'+pageId+".html",function (data) {
/* data is the pure html returned from get method, load it to your page */
$('#LoadViewsbyPageId').html(data);
});
} else {
$("#LoadViewsbyPageId").hide();
}
}
<!-- Load jQuery from Google's CDN -->
<!-- Load jQuery UI CSS -->
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<!-- Load jQuery JS -->
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<!-- Load jQuery UI Main JS -->
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
$("p:first").css("border","3px solid red");$("p:last").css("border","3px solid red");$("p:odd").css("border","3px solid red");$("p:even").css("border","3px solid red");$("p:gt(1)").css("border","3px solid red");$("p:eq(1)").css("border","3px solid red");$("p:not(p:eq(1))").css("border","3px solid red");| Filter | Purpose |
|---|---|
| :first | selects only the first instance of the selector's returned set |
| :last | selects only the last instance of the selector's returned set |
| :even | selects only even numbered elements of the selector's returned set |
| :odd | selects only odd numbered elements of the selector's returned set |
| :eq(n) | filters out elements that are positioned at the given index |
| :gt(n) | include elements that are past the given index |
| :lt(n) | include elements that are before the given index |
| :header | select all header elements (H1, H2, H3 etc) |
| :animated | selects all elements that are currently being animated in some way |
| :not(selector) | includes elements that do not match the given selector |
$(window).scroll(function() {
if($(window).scrollTop() > 0) {
$('#maincontent').css("background","gray");
} else {
$('#maincontent').css("background","white");
alert("Now you are in the top");
}
});
<body onscroll="bodyScroll();"></body>
bodyScroll() function function bodyScroll() {
$('#maincontent').css('background-color','lightGrey');
if (scrollTimer != -1)
clearTimeout(scrollTimer);
scrollTimer = window.setTimeout("scrollFinished()", 300);
}
scrollFinished() method. function scrollFinished() {
$('#maincontent').css("background","white");
}
$("p, li.b").css("border","3px solid red");
$("ul li.a").css("border","3px solid red");
$("ul+p").css("border","3px solid red");
$("#list1 ~ p").css("border","3px solid red");
<!DOCTYPE html >
<html>
<head>
<title>Document</title>
<script type="text/javascript" src="Scripts/jquery-1.11.3.js"></script>
<script >
$("document").ready(function(){
//Your jquery code run when document is ready
});
</script>
<style type="text/css">
.a { color: Navy; }
.b { color: Maroon; }
</style>
</head>
<body>
<ul id="list1">
<li class="a">item 1</li>
<li class="a">item 2</li>
<li class="b">item 3</li>
<li class="b">item 4</li>
</ul>
<p class="a">This is paragraph 1</p>
<p>This is paragraph 2</p>
<p class="b">This is paragraph 3</p>
<p>This is paragraph 4</p>
</body>
</html> This is the code for the html file
$("p").css("border","3px solid red");
$("#list1").css("border","3px solid red");
This will get all elements that has ID of "list1" and put a red border around it
$(".a").css("border","3px solid red");
$("p.b").css("border","3px solid red");
<!DOCTYPE html>
<html>
<head>
<script src="Scripts/jquery-1.11.3.js"> </script>
</head>
<body>
<div id="div1"> <h2> Let jQuery AJAX Change This Text </h2> </div>
<button>Get External Content</button>
<script>
$(document).ready(function(){
$("button").click(function(){
$("#div1").load("demo_test.txt");
});
});
</script>
</body>
</html>
When you click the button JQuery load() method will load the content of the file demo_test.txt to div element which has ID div1.