

If bold does actually refer to a CSS class, you can always specify both in the class property - i.e. Better still would be to change the class name from bold to 'tcol1', so you don't get any accidental inclusions into the jQuery results. for the example above I'd use your selection by class. Just make sure you're unique in your classnames. It may not be ideal as they have a class specified that may not exist, but it makes the selection a hell of a lot easier. Personally, what I've done in the past is give them a common class id and used that to select them. Let elArr = įor(let i=0 i console.log(`$`)) $(document.getElementsByName("tcol1")).hide() ĭocument.getElementsByName("tcol1").forEach(e=>e.style.display='none') ĭocument.querySelectorAll('').forEach(e=>e.style.display='none') Return document.getElementsByName("tcol1") Return $(document.getElementsByName("tcol1")) big table - 1000 rows - you can run test HERE.small table - 3 rows - you can run test HERE.

I perform two tests for read elements by name ( A, B, C, D) and hide that elements (E,F,G,H,I) getElementByName (G) and querySelectorAll (H) solutions are quite slow for big tables.jquery (E) and querySelectorAll (H) solutions are slowest for small tables.jquery (E) solution is quite-fast on big tables.

hide() jQuery method set style "default:none" on hidden elements - but it looks that they find faster way of do it than ='none' surprisingly the precalculated solution (I) is slower than jquery (E,F) solutions for big tables (!!!) - I check that.surprisingly the mixed js-jquery solution (F) is fastest on all browsers.Get rows by name and hide them (we exclude precalculated native solution (I) - theoretically fastest) from comparison - it is used as reference) mixed js-jquery solution (B) is faster than querySelectorAll (D) solution.

#Get name of element jquery code#
First, the code given to you in the Accepted Answer: $("#ID").attr("name") Īnd second, the Vanilla JS version of it: document.getElementById('ID').getAttribute("name") With that in mind, here are two pieces of code. Judging by the current accepted answer, I am going to assume that you were able to add an ID attribute to your element and use that to select it. While there is no denying that jQuery is a powerful tool, it is a really bad idea to use it for such a trivial operation as "get an element's attribute value".
