Here we are showing how to expand a div to full screen. See the demo and do it.
Sample code and demo is here
Demo
$( ".selector" ).dialog({2) Add the below line of code to your page
modal: false
});
$.fn.modal.Constructor.prototype.enforceFocus = function (){};
<ul>
<li id="foo">foo</li>
<li id="bar">bar</li>
<li id="baz">baz</li>
</ul>
var listItem = document.getElementById( "bar" );We get back the zero-based position of the list item:
console.log( "Index: " + $( "li" ).index( listItem ) );
jQuery.getScript()Load a JavaScript file from the server using a GET HTTP request, then execute it.
Eg:By default, $.getScript() sets the cache setting to false. This appends a timestamped query parameter to the request URL to ensure that the browser downloads the script each time it is requested. You can override this feature by setting the cache property globally using $.ajaxSetup():
$.getScript( "ajax/test.js", function( data, textStatus, jqxhr ) {
console.log( data ); // Data returned
console.log( textStatus ); // Success
console.log( jqxhr.status ); // 200
console.log( "Load was performed." );
});
$.ajaxSetup({Sample code and demo
cache: true
});
.serialize( )Eg:
<form>The .serialize() method can act on a jQuery object that has selected individual form elements, such as <input>, <textarea>, and <select>. However, it is typically easier to select the <form> tag itself for serialization:
<div><input type="text" name="a" value="1" id="a" /></div>
<div><input type="text" name="b" value="2" id="b" /></div>
<div><input type="hidden" name="c" value="3" id="c" /></div>
<div>
<textarea name="d" rows="8" cols="40">4</textarea>
</div>
<div><select name="e">
<option value="5" selected="selected">5</option>
<option value="6">6</option>
<option value="7">7</option>
</select></div>
<div>
<input type="checkbox" name="f" value="8" id="f" />
</div>
<div>
<input type="submit" name="g" value="Submit" id="g" />
</div>
</form>
$('form').submit(function()This produces a standard-looking query string:
{
alert($(this).serialize());
return false;
});
a=1&b=2&c=3&d=4&e=5Warning: selecting both the form and its children will cause duplicates in the serialized string.
$( ".selector" ).autocomplete({Final code and demo is here
source: [ "c++", "java", "php", "coldfusion", "javascript", "asp", "ruby" ]
});
var str = " hello, how are you? ";Method 2: using regex
str.trim(); //hello, how are you?
var str = " hello, how are you? ";Method 3: using JQuery
str.replace(/^\s+|\s+$/gm,''); //hello, how are you?
$.trim(" hello, how are you? "); //hello, how are you?Final code and demo is here
<div class="well PageContent"></div>Add this script in to your JavaScript section
<ul class="PaginationLinks pagination-sm"></ul>
$('.PaginationLinks').twbsPagination(Final code and demo is here
{
totalPages: 20,
visiblePages: 7,
onPageClick: function (event, PageNo) {
$('.PageContent').text('Page ' + PageNo);
}
});
var Name = prompt("Please enter your name");Final code and demo is here
if (Name !== null)
{
if (Name !== "")
{
//If the user clicks OK with text
}
else
{
//If the user clicks OK without entering any text
}
}
<input type="text" id="SearchKeyword"/>
<button type="button" onclick="Search()">Search</button>
<script>Final code and demo is here
//Using JQuery
$('#SearchKeyword').keyup(function(e)
{
if(e.keyCode == 13)
{
$(this).trigger("enterKey");
}
});
//Using JavaScript
document.getElementById("SearchKeyword").onkeypress = function(e)
{
if (e.keyCode === 13)
{
alert("Enter key pressed");
Search();
}
};
</script>
<div data-website-name="webspeckle.com"></div>In the above example 'div' element has an attribute "data-website-name". This is a custom data attributes. The string "webspeckle.com" set to "data-website-name" attribute.
<div data-website-name="webspeckle.com" data-website-data='{"name":"webspeckle.com","type":"blog"}'></div>In the above example the JSON string '{"name":"webspeckle.com","type":"blog"}' set to the 'data-website-data' attribute.
$("div").data("data-website-name") //webspeckle.comSet value to data attribute using JQuery
$("div").data("data-website-data") //JSON Object
$("div").data("data-website-data").type //blog
<script>Final code and demo is here
var car =
{
color: "red",
owner: "rahul"
}
$(document).ready(function()
{
$("div").data("car",car)
});
</script>
<script>1) Catch the 'keydown' event
$(document).bind('keydown', function (e)
{
if (e.ctrlKey && (e.which === 83)) //Ctrl+S
{
e.preventDefault();
alert('Ctrl+S Pressed');
return false;
}
});
</script>
<script>Some control key combinations have been reserved for browser usage only and can no longer be intercepted by the client side JavaScript in the web page.
document.onkeydown=function(e)
{
var e = e || window.event; // for IE to cover IEs window object
if(e.altKey && e.which === 83)
{
alert('Alt+S Pressed');
return false;
}
};
</script>
new RegExp("Keyword",'gim')And replace the keyword by '<span class=\"Highlight\">Keyword</span>'
<style>JQuery 'unwrap()' methord is used for unwrap the previously highlighted elements.
.Highlight
{
background-color:#FF9;
color:#555;
}
</style>
<script>Final code and demo is here
$(document).ready(function()
{
$("p").text("Anchor element url = "+$("a").attr("href"));
$("button").click(function()
{
$("a").attr("href","http://www.webspeckle.com");
$("p").text("Anchor element url = "+$("a").attr("href"));
});
});
</script>
<script>Final code and demo is here
function Blink(Element,Speed)
{
Element.animate({opacity: 0.2},Speed,function()
{
Element.animate({opacity: 1.0},Speed,function()
{
Blink(Element,Speed);
});
});
}
$(document).ready(function()
{
Blink($(".Warning"),200); //400 = Blinking Speed
});
</script>
$('[data-toggle="popover"]').popover(options);You must be set the "trigger" option to "manual" for showing one popover at a time.
$('[data-toggle="popover"]').popover({'trigger': 'manual'});Then you should catch the click event. Show the current popover and hide others
$('[data-toggle="popover"]').on('click', function (e)The final code & demo is here
{
$(this).popover('show');
$('[data-toggle="popover"]').not(this).popover('hide');
});
Math.random()The random() method returns a random number from 0 (inclusive) up to but not including 1 (exclusive).
function GetRandomHexColor()A demo for changing the border color and text color of a div by using JQuery.
{
var AllowedLetters = '0123456789ABCDEF';
var Color = '#';
for (var i = 0; i < 6; i++ )
{
Color += AllowedLetters[Math.floor(Math.random() * 16)];
}
return Color;
}
function ucwords(str)Eg:
{
return str === null ? "" : str.toLowerCase().replace(/^(.)|\s+(.)/g, function ($1)
{
return $1.toUpperCase();
});
}