Skip to the content.

PequeJS

A small Javascript library for manipulate DOM and send AJAX requests

Parameters

Examples

$(document)
$('input#username')
$('a', this)

Returns object PequeJS object.

Meta

Constructor

Create the constructor

Parameters

html

Return the HTML of the firs element or set the HTML for one or more elements.

Parameters

Examples

$('p').html();
$('p#title').html('<strong>PequeJS</strong>');

Returns string the HTML of the firts element found if html variable is not set.

text

Return the text of the firs element or set the text for one or more elements.

Parameters

Examples

console.log($('span').text());
$('span#username').text('Son Link');

Returns string the HTML of the found element if html variable is not set.

on

Add event to the elements.

Parameters

Examples

$('button').on('click', function() {
 alert('You clicked');
});

Returns undefined Returns undefined if event and callback parameters are empty.

show

Display the element(s).

Parameters

Examples

$('#modal').show();
$('.blocks').show('flex');

hide

Hide the element(s).

Examples

$('#modal').hide();

attr

Set a element attribute or return the attribute of the firts element found.

Parameters

Examples

$('#mylink').attr('href', 'https://google.es');
link = $('#mylink').attr('href');

Returns string The attribute value of the first element found if value is not set.

removeAttr

Remove a element(s) attribute.

Parameters

Examples

$('input#name').removeAttr('disabled');

append

Append a text or HTML to element(s).

Parameters

Examples

$('ul#series').append('<li>The Rookie</li>');

empty

Clear all content of the element(s).

Examples

$('#series').empty();

hasClass

Return if any element have the class name.

Parameters

Examples

$('#modal').hasClass('show');

Returns boolean true if any element has the class or false if not.

addClass

Add class(es) to each element(s). You can add more than one separated by spaces.

Parameters

Examples

$('#modal').addClass('show');
$('span#username').addClass('bold color-red');

removeClass

Remove class(es) on each element. You can remove more than one separated by spaces.

Parameters

Examples

$('#modal').removeClass('show');
$('span#username').removeClass('bold color-red');

toggleClass

Toggle class on each element.

Parameters

Examples

$('#modal').toggleClass('show');

val

Get or set the value for input, textarea or select.

Parameters

Examples

$('#modal').toggleClass('show');

is

Checks if the current set of elements match a selector and returns true if at least one of these elements matches the given arguments.

Parameters

Examples

$('input').is(':valid')
$('#accept-terms').is(':checked')

Returns any Bool

trigger

Trigger a event for the element.

Parameters

Examples

$('#myform').trigger('submit')

each

Iterate through every element of the collection. The callback function receive the current element.

Parameters

Examples

$('ul#series').each(function(ele) {
 series.push($(ele).text());
});

Returns object The actual element

ajax

Perform an Ajax request.

Parameters

Examples

$().ajax('http://localhost/api', {
 data: {
   user: 'myuser',
   passwd: '123456'
 },
 type: 'POST',
 success: function(response) {
   console.dir(response);
 }
});

get

Perform an GET request. This is a alias for $().ajax.

Parameters

Examples

$().get('http://localhost/api?key=123456789',
 function(response) {
   console.dir(response);
 }
);
$().get('http://localhost/api', {key: '123456789'},
 function(response) {
   console.dir(response);
 }
);

post

Perform an POST request. This is a alias for $().ajax.

Parameters

Examples

$().post('http://localhost/api', {key: '123456789'},
 function(response) {
   console.dir(response);
 }
);

instance

Create a new instance of the constructor

Parameters

Returns object The instance of the library.

instance

Return the constructor instantiation