Is there a way in JavaScript to remove the end of a string? I need to only keep the first 8 characters of a string and remove the rest. Answer You are looking for JavaScript’s String method substring e.g. Which returns the string starting at the first character and finishing before the 9th character – i.e. ‘Hiya how’. substring documentation
Tag: javascript
Split the sentences by ‘,’ and remove surrounding spaces
I have this code: Looks like the whole string has been matched, but where has “b” gone? I would rather expect to get: so that I can do m.shift() with a result like s.split(‘,’) but also with whitespaces removed. Do I have a mistake in the regexp or do I misunderstand String.prototype.match? Answer so finally i went with /(?=S)[^,]+?(?=s*(,|$))/g, which
Add 10 seconds to a Date
How can I add 10 seconds to a JavaScript date object? Something like this: Answer There’s a setSeconds method as well: For a list of the other Date functions, you should check out MDN setSeconds will correctly handle wrap-around cases:
How to solve different FPS in requestAnimationFrame on different browsers?
How to solve different FPS in requestAnimationFrame on different browsers? I am making a 3D game using THREE.js that uses requestAnimationFrame and it is fast on Google Chrome 15. However, it is really slow on Firefox 6 and really really slow (slower than Firefox) on IE9. This is really a big problem and I am wondering if there is a
jQuery: Checking if next element exists
Is there a way to check if a next element exists? Check my code: What am I doing wrong? Thanks a lot! Answer Have you tried looking at .next(‘li’).length?
jQuery datatables ajax callback
I am using jQuery DataTables and doing server-side data. I’m trying to call a function when the ajax call returns. I tried inserting this fnCallback2 which calls my function and the original function, but jQuery just throws an error (and doesn’t tell me what the error is) and skips out. I also tried adding the fnInitComplete parameter, but that only
Javascript library for human-friendly relative date formatting [closed]
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations. Closed 7 years ago. Improve this question I’d like to display some dates as relative to the current
Linked Dynamic Radio Buttons HTML Javascript
All, Have used this site a few times before and had some great replies so hopefully someone can help again. I want a set of radio buttons, so that when you click a button – you get another set below it. Then again, when you click one of the 2nd set of buttons, you’ll get a third etc. Currently I
If domain specified not equal to then current URL apply this jQuery as well as pages with same domain
The code below only shows <span> on http://example.com/ but wont show <span> on http://example.com/files/target.html so how can I get it to work on all pages with the specified domain? Please help. Answer What you wrote doesn’t work because window.location returns a Location object, which is a host object. The variable myurl is a string. When comparing a string and an
Confused with syntax, calling a JS function with an input button
I am having troubles understanding the xhtml syntax for calling a function with an input button. I have searched for this, but cannot find a clear explanation. This snippet of code is from my book, and it works ok, but I’m not sure exactly how the following line works: From what I can figure out, gradeForm is the form, and