[Solved] Javascript and singleton pattern

Yes, you need to export mySingleton by assigning it to module.exports. You also have a syntax error in your code (one of your braces is in the wrong place). Fixing those two things, you get: var mySingleton = (function() { var instance; function init() { var privateRandomNumber = Math.random(); return { getRandomNumber : function() { … Read more

[Solved] Javascript to check if div has child with that classname [closed]

try the following: $(“.item-card”).click(function() { var itemnume = $(this).find(“img”).attr(“title”); var replaced = itemnume.split(‘ ‘).join(‘_’); if ($(this).hasClass(‘selected-item’)) { console.log() $(“#” + replaced).remove(); } else { $(“#itemcart”).append($(“<div id=” + replaced + “>” + itemnume + “</div>”)); } $(this).toggleClass(“selected-item”); }); https://jsfiddle.net/0tusd19b/ 40 solved Javascript to check if div has child with that classname [closed]

[Solved] Combine Array Of Strings With String

const loginUser = “[email protected]” const old = [ { “toAddresses”: [“[email protected]”, “[email protected]”], }, { “fromAddress”: “[email protected]”, “toAddresses”: [“[email protected]”, “[email protected]”], } ]; let last = old[old.length – 1]; let combined = new Set([last.fromAddress, …last.toAddresses]); combined.delete(loginUser); let newResponse = Array.from(combined); console.log({newResponse}); solved Combine Array Of Strings With String

[Solved] How can I make my header smaller if i will scroll down the webpage [closed]

Are you looking for something like this? $(function () { $(window).scroll(function () { if ($(window).scrollTop() > 5) $(“header”).addClass(“small”); else $(“header”).removeClass(“small”); }); }); * {margin: 0; padding: 0; list-style: none; font-family: ‘Segoe UI’;} body {padding-top: 100px;} p {margin: 0 0 10px;} header {height: 100px; line-height: 100px; text-align: center; background-color: #ccf; position: fixed; left: 0; top: 0; … Read more

[Solved] For condition running only once when calling JS File

What @Lloyd said is correct, the + i is necessary to make unique pairs. Try this: for (int i = 0; i <= 2; i++) { Page.ClientScript.RegisterStartupScript(GetType(), “a”+ i, “foo(‘hello’);”, true); } You were missing the semicolon at the end of the javascript function. This is what was being generated with what @Lloyd suggested <script … Read more

[Solved] jQuery on second hover event

Store a counter in the data of each element and increment it on each hover, if it gets to two, do your magic: HTML: <div class=”items”> <div class=”hover-me” data-hovercount=”0″></div> <div class=”hover-me” data-hovercount=”0″></div> <div class=”hover-me” data-hovercount=”0″></div> </div> JS: $(“.hover-me”).on(‘mouseenter’, function() { var $this = $(this), $this.data(‘hovercount’, parseInt($this.data(‘hovercount’)) + 1); if ($this.data(‘hovercount’) == 2) { //do something. … Read more

[Solved] capture image clicked in one page and display the same in another page HTML

Page 1: <%@ page language=”java” contentType=”text/html; charset=ISO-8859-1″ pageEncoding=”ISO-8859-1″%> <!DOCTYPE html PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” “http://www.w3.org/TR/html4/loose.dtd”> <html> <head> <meta http-equiv=”Content-Type” content=”text/html; charset=ISO-8859-1″> <title>Page 1</title> <script type=”text/javascript”> function filename(){ var fullPath = document.getElementById(“image”).src; var filename = fullPath.replace(/^.*[\\\/]/, ”); var fileid = filename.split(“\.”)[0];; window.location.href = “https://stackoverflow.com/questions/37542650/test2.jsp?imgid=”+fileid; } </script> </head> <body> <IMG id=”image” SRC=”images/1.png” width=”100px” alt=”Logo” onclick=”filename();”> </body> … Read more

[Solved] How to put javascript in html file

Following can be a reason for your issue Invalid src path in the script tag Javascript might be disabled in your browser. You have a script error/exception that stopped entire page’s script execution. Maybe you have an Ajax request that won’t work if your open it as a local file protocol. e.g., file:// What can … Read more

[Solved] Kendo UI Grid – Add/Remove filters dynamically

In order to filter by text box you can hook up a keyUp event in order to retrieve the value. You can then add this as a filter to the existing filter object. $(‘#NameOfInput’).keyup(function () { var val = $(‘#NameOfInput’).val(); var grid = $(“#yourGrid”).data(“kendoGrid”); var filter = grid.dataSource.filter(); filter.filters.push({ field: “NameOfFieldYouWishToFilter”, operator: “eq”, value: val, … Read more

[Solved] How to create custom type in angular [closed]

It depends on what you mean by type exactly. If you want to define a “type” that you can use in TypeScript strong typing, then you have several choices. You can build an interface like this: export interface Product { productId: number; productName: string; productCode: string; releaseDate: string; price: number; description: string; starRating: number; imageUrl: … Read more

[Solved] Access property within javascript object [duplicate]

Use for…in to iterate over the keys of the object and check if your inner object contains your property var o = { “title_can_change”:{ property: 1 } }; for (var k in o) { if (o.hasOwnProperty(k) && o[k].property) { return o[k].property; } } 0 solved Access property within javascript object [duplicate]