[Solved] Show more/less on PHP value

Here’s a JS method. I will work on controlling the character count but for now…. window.onload = function() { let rm = document.querySelectorAll(‘.readmore’); rm.forEach(el => { el.classList.add(‘less’); var div = document.createElement(‘div’); div.innerHTML = “<a href=”https://stackoverflow.com/questions/67731164/javascript:void(0);” class=”rmlink” onclick=’toggleRM(this)’>Read more</a>”; el.append(div); }) } function toggleRM(el) { const cl = el.parentNode.parentNode.classList const is_less = cl.contains(‘less’); el.innerHTML = !is_less … Read more

[Solved] How do I reduce this code to one line?

See Frits’ answer: You can, but is there really any need? It’s nice and readable the way you’ve done it. But if you really, really want to, this is how: exports.about = function(req, res){ res.render(‘about’, {title: ‘about page’, time: new Date().toLocaleDateString() }); }; It looks a bit odd, but the new Date() part takes precedence, … Read more

[Solved] How could I make a calendar? [closed]

javascript date object is pretty handy. You can do something like this to get current dates of the current month: const today = new Date() const date = new Date() date.setDate(1) var calendar=”” for(var i = 0; i < 31; i++) { if(date.getMonth() == today.getMonth()) { calendar += `<div onclick=”openModal()”>${date.getDate()}</div> ` } } This is … Read more

[Solved] recursion javascript, ask for answer

and totally redeem yourself ! SO likes to punish people if they don’t show their work, but I’m not one to judge. I do think you will learn more if you try these problems on your own, but I know what it’s like to be completely bewildered; and no good-natured soul amongst us wants to … Read more

[Solved] jQuery : Hide select DOM elements created on the fly

This can be achieved with a single line that manipulates the DOM using the append, filter and hide jQuery methods. $(‘selector2’).append(thingo) – append the items .filter(‘selector1’) – of the original selector, only select those matching the filter .hide() – hide the filtered items Like this: $(function() { var thingo = $(‘<div />’); $(‘selector2’).append(thingo).filter(‘selector1’).hide(); } Optionally, … Read more

[Solved] Transform an array to another array

As charlietfl said, in the future posts you must provide examples of code, that you’ve written to solve your problem. Here’s the solution, it’s pretty simple: const initialObject = { “items”: [ { “_id”: “admin”, “authorities”: [ { “name”: “ROLE_ADMIN” } ] }, { “_id”: “user”, “authorities”: [ { “name”: “ROLE_USER” } ] } ] … Read more

[Solved] Syntactic sugar JavaScript ( If statement) Error [closed]

I try to use syntactic sugar The conditional operator is not syntactic sugar. It’s a specific operator with a specific purpose, and you’re simply using it incorrectly. It is used for conditionally producing a value as an overall expression, one value if the condition is true and another if it’s false. For example: let x … Read more