Getting DOM element value using pure JavaScript

Update: The question was edited. Both of the solutions are now equivalent. Original answer Yes, most notably! I don’t think the second one will work (and if it does, not very portably). The first one should be OK. // HTML: <input id=”theId” value=”test” onclick=”doSomething(this)” /> // JavaScript: function(elem){ var value = elem.value; var id = … Read more

How to remove elements that were fetched using querySelectorAll?

Yes, you’re almost right. .querySelectorAll returns a frozen NodeList. You need to iterate it and do things. Array.prototype.forEach.call( element, function( node ) { node.parentNode.removeChild( node ); }); Even if you only got one result, you would need to access it via index, like elements[0].parentNode.removeChild(elements[0]); If you only want to query for one element, use .querySelector … Read more

document.querySelector multiple data-attributes in one element

There should not be a space between the 2 selectors document.querySelector(‘[data-point-id=”7febe088-4eca-493b-8455-385b39ad30e3″][data-period=”current”]’) if you give a space between them it will become a descendant selector, ie it will search for an element attribute data-period=”current” which is inside an element with data-point-id=”7febe088-4eca-493b-8455-385b39ad30e3″ like <div class=”text-right” data-point-id=”7febe088-4eca-493b-8455-385b39ad30e3″> <div data-period=”current”>-</div> </div>

jquery, find next element by class

In this case you need to go up to the <tr> then use .next(), like this: $(obj).closest(‘tr’).next().find(‘.class’); Or if there may be rows in-between without the .class inside, you can use .nextAll(), like this: $(obj).closest(‘tr’).nextAll(‘:has(.class):first’).find(‘.class’);

How to count identical string elements in a Ruby array

Ruby v2.7+ (latest) As of ruby v2.7.0 (released December 2019), the core language now includes Enumerable#tally – a new method, designed specifically for this problem: names = [“Jason”, “Jason”, “Teresa”, “Judah”, “Michelle”, “Judah”, “Judah”, “Allison”] names.tally #=> {“Jason”=>2, “Teresa”=>1, “Judah”=>3, “Michelle”=>1, “Allison”=>1} Ruby v2.4+ (currently supported, but older) The following code was not possible in … Read more

Get the string representation of a DOM node

You can create a temporary parent node, and get the innerHTML content of it: var el = document.createElement(“p”); el.appendChild(document.createTextNode(“Test”)); var tmp = document.createElement(“div”); tmp.appendChild(el); console.log(tmp.innerHTML); // <p>Test</p> EDIT: Please see answer below about outerHTML. el.outerHTML should be all that is needed.

Common elements in two lists

Use Collection#retainAll(). listA.retainAll(listB); // listA now contains only the elements which are also contained in listB. If you want to avoid that changes are being affected in listA, then you need to create a new one. List<Integer> common = new ArrayList<Integer>(listA); common.retainAll(listB); // common now contains only the elements which are contained in listA and … Read more

Number of elements in a javascript object

Although JS implementations might keep track of such a value internally, there’s no standard way to get it. In the past, Mozilla’s Javascript variant exposed the non-standard __count__, but it has been removed with version 1.8.5. For cross-browser scripting you’re stuck with explicitly iterating over the properties and checking hasOwnProperty(): function countProperties(obj) { var count … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)