How to use jQuery with Angular?

Using jQuery from Angular2 is a breeze compared to ng1. If you are using TypeScript you could first reference jQuery typescript definition. tsd install jquery –save or typings install dt~jquery –global –save TypescriptDefinitions are not required since you could just use any as the type for $ or jQuery In your angular component you should … Read more

jQuery removeClass wildcard

The removeClass function takes a function argument since jQuery 1.4. $(“#hello”).removeClass (function (index, className) { return (className.match (/(^|\s)color-\S+/g) || []).join(‘ ‘); }); Live example: http://jsfiddle.net/xa9xS/1409/

JavaScript console.log causes error: “Synchronous XMLHttpRequest on the main thread is deprecated…”

This happened to me when I was being lazy and included a script tag as part of the content that was being returned. As such: Partial HTML Content: <div> SOME CONTENT HERE </div> <script src=”https://stackoverflow.com/scripts/script.js”></script> It appears, at least in my case, that if you return HTML content like that via xhr, you will cause … Read more

How do you convert a jQuery object into a string?

I assume you’re asking for the full HTML string. If that’s the case, something like this will do the trick: $(‘<div>’).append($(‘#item-of-interest’).clone()).html(); This is explained in more depth here, but essentially you make a new node to wrap the item of interest, do the manipulations, remove it, and grab the HTML. If you’re just after a … Read more

jQuery Selector: Id Ends With?

If you know the element type then: (eg: replace ‘element’ with ‘div’) $(“element[id$=’txtTitle’]”) If you don’t know the element type: $(“[id$=’txtTitle’]”) More information available // the old way, needs exact ID: document.getElementById(“hi”).value = “kk”; $(function() { $(“[id$=’txtTitle’]”).val(“zz”); }); <script src=”https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js”></script> <input id=”ctl_blabla_txtTitle” type=”text” />

Toggle Checkboxes on/off

You can write: $(document).ready(function() { $(“#select-all-teammembers”).click(function() { var checkBoxes = $(“input[name=recipients\\[\\]]”); checkBoxes.prop(“checked”, !checkBoxes.prop(“checked”)); }); }); Before jQuery 1.6, when we only had attr() and not prop(), we used to write: checkBoxes.attr(“checked”, !checkBoxes.attr(“checked”)); But prop() has better semantics than attr() when applied to “boolean” HTML attributes, so it is usually preferred in this situation.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)