Sources:https://api.jquery.com/category/selectors/, https://j11y.io/javascript/regex-selector-for-jquery/
$(function(){// Do some thing here...});#Selectors-
$("#ELEMENT_ID").text(); //returns body of selected element.
$("#ELEMENT_ID").val(); //returns value of selected element.$("#ELEMENT_ID").attr('ATTRIBUTE') //returns value of attribute in selected element.$("#ELEMENT_ID").trigger("click"); //triggers click event on element.
$("TAG[ATTRIBUTE='ATTRIBUTE_VALUE']").... //selects element with tag-TAG with attribute-ATTRIBUTE and attribute_value-ATTRIBUTE_VALUE.#e.g. Selectors:
var element = $('img');element = element.filter('[title^="Black quartz"]');element = element.filter(function(){return $(this).attr("title").toLowerCase().indexOf("Black quartz".toLowerCase())>-1})#Iterate over all attributes of element where event occurred.
function clickHandler(e){ var htmlText = ''; $.each(e.toElement.attributes, function() { if(this.specified) { htmlText += "<tr><td>" + this.name + "</td><td><input type='text' value='" + this.value + "'/></td></tr>"; } });}#Search regex in text.
var matches = $('body').text().match(/ORDER_NUMBER:\s?([A-Z\d]+)/);if (matches[1]) { console.log(matches[1]); // 22M123456JK98766}#Asynchronous file upload.
$('#submitBtn').click(function (e) { $.ajax({ url: 'http://localhost:10016/com.<ORGANISATION>.api/v1/upload',//that accepts multipart form data type: 'POST', data: new FormData($('form')[0]), //asuming there is first form that hold input type file cache: false, contentType: false, processData: false, }).done(function(e){alert("Done");}).fail(function(e){alert(e)});});#Show/Hide elements with animation.
$('#<ELEMENT_ID>').hide(1000); #hides in 1 second with animation$('#<ELEMENT_ID>').show(1000); #shows in 1 second with animation$(document).ready(function () { $("#productsTbl").DataTable({ "processing": true, "serverSide": true, "ajax": serviceURL + "products", //URL which serves data in sepecified format. {draw:<sent as queryParam>, ..., data:[<OBJECTS/ARRAYS>]} "columns": [ { "data": "a" }, { "data": function(data){return JSON.stringify(data['oas']);} } ] });});Problem#1: Ajax request returns 200 OK, but an error event is fired instead of success
Soln: Removed dataType:json from request. stackoverflow