Javascript Replace String in String

let text = “The dogs barked loudly”; let result = text.replace(“dogs”, “cats”); Replace all instances: let text = “The dogs barked loudly”; let result = text.replace(“dogs/g”, “cats”);

Read More

Javascript Does String Contain Substring

var str = “Some haystack text goes here that contains needlestring”;   str.includes(‘needlestring’); If you get an error, like “TypeError: e.includes is not a function”, it probably means that you’re trying to do a search on something that isn’t a string or an array.   Fix this by converting the variable to a string, like: element.toString().includes(“#”);

Read More

Get Current Clicked on Element in Javascript

event.currentTarget

Read More

Javascript Capture Camera on Phone Doesn’t Work on iPhone

On an iphone you need to add a ‘playsinline’ parameter. I think it works by placing it either in the javascript, or as part of the HTML tag — I just added it to both to be safe, and it resolved the issue so I called it good. In javascript as part of the getUserMedia […]

Read More

Document Ready in Vanilla Javascript

To wait until the document is ready, similiar to the $(document).ready functionality in jQuery, just do this: document.addEventListener( ‘DOMContentLoaded’, function(e) {    Stuff Here })

Read More

Javascript – Show or Hide an Element

Showing or hiding an element with javascript: (use “#” for elements by ID, or “.” for elements by class) document.querySelector(“#element”).style.display = ‘block’; document.querySelector(“#element”).style.display = ‘none’;

Read More

PHP JSON Returned As Object Instead of Array

I was returning, what I thought was an array from PHP, but it kept returning it as a json object, so I had something like: $listItem[0][0] = “Jan 1”; $listItem[0][1] = 100; $listItem[1][0] = “Jan 2”; $listItem[1][1] = 120; $listItem[2][0] = “Jan 2”; $listItem[2][1] = 120; …etc… This would return in javascript those an array, […]

Read More

A Simple Slideout Menu

I just wanted an easy slideout menu.  Click on a link, and the menu slides out from the left side of the screen.  Click on the link again, or somewhere else on the page, and the menu slides back in.  Here it is: HTML Code data-openwidth is the width in pixels of however wide you […]

Read More

Enhancements for jPlayer Implementation

I love the jPlayer for easily being able to add modern mp3 support to web pages.  I wanted a few additional features, so I created this additional script which adds a few updated features: Adding rewind/fast-forward support Ability to toggle the volume controls on and off Ability to specify the mp3 url by setting a […]

Read More

Preserving Click Events With jQuery UI

My click events weren\’t being preserved when using the jquery sortable functionality.  After dragging a list item around, elements like my checkboxes would no longer work, and not just for the element that was being dragged, but for any of the checkboxes in the entire list.  It took a bit of searching, but to get […]

Read More