Wednesday, September 27, 2017
Get int or float number from a string
Number("this a test (12.75%)".match(/\d*\.*\d+/g)[0]); // Output: 12.75
Etiquetes de comentaris:
JavaScript,
RegExp
Tuesday, October 25, 2016
Sort DOM elements by jQuery
HTML:
<ul class="alphaList">
<li>apples</li>
<li>cats</li>
<li>bears</li>
</ul>
JavaScript/jQuery:
var elems = $('.alphalist li').detach().sort(function (a, b) {
return ($(a).text() < $(b).text() ? -1
: $(a).text() > $(b).text() ? 1 : 0);
});
$('.alphalist').append(elems);
<ul class="alphaList">
<li>apples</li>
<li>cats</li>
<li>bears</li>
</ul>
JavaScript/jQuery:
var elems = $('.alphalist li').detach().sort(function (a, b) {
return ($(a).text() < $(b).text() ? -1
: $(a).text() > $(b).text() ? 1 : 0);
});
$('.alphalist').append(elems);
Note: jQuery detach() gets (removing) elements from DOM.
Etiquetes de comentaris:
jquery
Thursday, March 10, 2016
jQuery Custom Events
Custom events allow data interchange between different modules or classes running in the current page.
These events are delivered as a broadcast. They are invoked with a "trigger" method, and catched with the "on" method.
Parameters are optional. If there are more than one, these have to be embedded in an array, yet the target methods must declare those parameters individually.
These events are delivered as a broadcast. They are invoked with a "trigger" method, and catched with the "on" method.
Parameters are optional. If there are more than one, these have to be embedded in an array, yet the target methods must declare those parameters individually.
Etiquetes de comentaris:
jquery
Subscribe to:
Posts (Atom)