Skip to content
Advertisement

Javascript: jQuery hide/show dynamic condition (datatables)

I am using the following strategy to tag my elements with classes so that I can hide/display based on a variable value.

JavaScript

Here is my test function im working on; _inviteFormat could be, email, postal or both

JavaScript

Goal: to push into elArray the name of the first class for all instances of elements on the page containing class _type and that no email class is present so that I can then hide these elements.

Current behaviour: Only the first element class name is being pushed into the array.

Here is a list of all the columns in my table enter image description here

I tried the following two scripts but they don’t work

JavaScript

Advertisement

Answer

That’s why, while $('._type') returns a collection of jQuery objects, as soon as you chain .attr('class') only the first element is returned.

Also, you have a typo (I guess) in the if condition (you wrote if(_inviteFormat='Email'), but should be if(_inviteFormat==='Email')).

Finally, in your 2 scripts you’re querying for .type but class name is ._type

This way it gets all irrelevant classes inside the array:

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement