How to remove leading and trailing rendered as white spaces from a given HTML string? [closed]

See the String method trim() – https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String/Trim var myString = ‘ bunch of <br> string data with<p>trailing</p> and leading space ‘; myString = myString.trim(); // or myString = String.trim(myString); Edit As noted in other comments, it is possible to use the regex approach. The trim method is effectively just an alias for a regex: if(!String.prototype.trim) … Read more

Accessing up-to-date state from within a callback

For your scenario (where you cannot keep creating new callbacks and passing them to your 3rd party library), you can use useRef to keep a mutable object with the current state. Like so: function Card(title) { const [count, setCount] = React.useState(0) const [callbackSetup, setCallbackSetup] = React.useState(false) const stateRef = useRef(); // make stateRef always have … Read more

Are there any benefits to Session Storage over Local Storage?

localStorage and sessionStorage both extend Storage. There is no difference between them except for the intended “non-persistence” of sessionStorage. That is, the data stored in localStorage persists until explicitly deleted. Changes made are saved and available for all current and future visits to the site. For sessionStorage, changes are only available per tab. Changes made … Read more

SharePoint 2013 get current user using JavaScript

Here is the code that worked for me: <script src=”https://stackoverflow.com/SiteAssets/jquery.SPServices-2013.02a.js” type=”text/javascript”></script> <script src=”/SiteAssets/jquery.js” type=”text/javascript”></script> <script type=”text/javascript”> var userid= _spPageContextInfo.userId; var requestUri = _spPageContextInfo.webAbsoluteUrl + “/_api/web/getuserbyid(” + userid + “)”; var requestHeaders = { “accept” : “application/json;odata=verbose” }; $.ajax({ url : requestUri, contentType : “application/json;odata=verbose”, headers : requestHeaders, success : onSuccess, error : onError }); function … Read more

How do I implement Toastr JS?

Toastr is a very nice component, and you can show messages with theses commands: // for success – green box toastr.success(‘Success messages’); // for errors – red box toastr.error(‘errors messages’); // for warning – orange box toastr.warning(‘warning messages’); // for info – blue box toastr.info(‘info messages’); If you want to provide a title on the … Read more

tech