[Solved] Check if value of one array is found in another [closed]

You can simlpy cycle through the second array, split at :, check the first part and, in case of a match, return the second function findX(value, arr) { for (var i = 0; i < arr.length; i++) { var toSplit = arr[i].split(‘:’); if (toSplit[0] === value) { return toSplit[1]; } } } console.log(findX(“User1-2”, [“User1-2:280”, “User2-2:280”, … Read more

[Solved] Repost/ asking again. Change event in Kartik’s bootstrap-slider extension for Yii2

You should always keep your console or developer bar open when working with javascript, you never know when something conflicts with the other. You need to use parseInt() to pass a value to the setValue function of the slider, it is interpreting it as text, otherwise, it throws Uncaught Error: Invalid input value ‘1’ passed … Read more

[Solved] How to make page loaders/animations/transitions

I go about it by providing different states for your page (eg. loading, loaded, and error). And passing in a status parameter, then using css to add a display: none class to it. (the hide class is display: none) function setStatus(status) { document.getElementById(“loading”).classList.add(“hide”); document.getElementById(“contents”).classList.add(“hide”); if (status == “loaded”) { document.getElementById(“contents”).classList.remove(“hide”); } if (status == “loading”) … Read more

[Solved] How to do the same in JavaScript? [closed]

If you want Vanilla JavaScript solution you can try this: function startCalc() { var root = document.documentElement || document.body; root.addEventListener(‘blur’, function(e) { var node = e.target; if (node.nodeName == ‘input’ && node.getAttribute(‘type’) == ‘text’) { var imekontrolebase = node.getAttribute(‘id’); var ime = imekontrolebase.substr(12, imekontrolebase.length); var n = ime.indexOf(“_”); var red = ime.substr(n+1); var imekol1 = … Read more

[Solved] Which ways are best to define my method.

So, you’ve proposed two functions that look like they are primarily designed to work with arrays, but they should return intelligent results if you pass them something other than an array. So, right away, you can’t use the Array.prototype method because if the data is not an array, that method won’t exist on the object … Read more

[Solved] Regular Expression to get text from css

If you have CSS styles isolated in a javascript string, you can get the width value with this regex: var re = /\.body\s*\{[^\}]*?width\s*:\s*(.*);/m; var matches = str.match(re); if (matches) { var width = matches[1]; } Test case here: http://jsfiddle.net/jfriend00/jSDeJ/. The height value can be obtained with this regex: \.body\s*\{[^\}]*?height\s*:\s*(.*);/m; If you just want the text … Read more

[Solved] Parsing webpages to extract contents

Suggested readings Static pages: java.net.URLConnection and java.net.HttpURLConnection jsoup – HTML parser and content manipulation library Mind you, many of the pages will create content dynamically using JavaScript after loading. For such a case, the ‘static page’ approach won’t help, you will need to search for tools in the “Web automation” category.Selenium is such a toolset. … Read more

[Solved] Given a string of html, how would i search and highlight a word?

This will highlight the first p element but if you have more than one it would be better to use an ID and find it by getElementById p = document.getElementsByTagName(‘p’); p[0].style.background= ‘yellow’ “<html> <body> <p style=”width:30px;”>Test</p> </body> </html>” 1 solved Given a string of html, how would i search and highlight a word?