2
I have a series of checkboxes in an interface that are already configured to display/hide other elements of the interface conditionally. In this same interface I have a div
set to display messages to the user also conditionally depending on the checkbox selected.
I did this example on jsfiddle based on another script, which uses . each in the function to check the inputs with a certain class and "print" the label text of these inputs in another element, in case a <span>
It turns out that in the "final" interface the checkbox and radio elements are customized and use the tag <label>
to define their styles, which in turn does not allow me to insert texts into the elements <label>
and so I can’t use that function...
There would be another, simpler and more coherent way to display conditional messages perhaps extracted from the attribute data-
?
Here is the code mentioned in the jsfiddle link.
That is not an answer friend, you must present your code and explain why to teach the one who asked the question.
– Gabriel Gartz
The code is there :)
– EduardoFernandes
now improved :)
– Gabriel Gartz
Thank you, this solves the issue of not being able to use text in the elements
<label>
, actually wear$.data("text")
makes a lot of sense. Now I was wondering if there wouldn’t be an even leaner function to simply "switch" between the different attributesdata-
of an element and display them in this same element. Please see the tag<span>
with the attributesdata-
defined. In this solution here https://jsfiddle.net/plan/z0n1moyu/ has a very coarse approach to check that checkboxes are marked and then "toggle" the values...– Adriano Monecchi
I found the solution that uses the
$.foreach()
quite elegant. It is simple and solves the problem clearly and quickly :).– EduardoFernandes
@Eduardofernandes good answer,
+1
. Perhaps semantically it makes more sense to use the.map()
. Tip only: https://jsfiddle.net/433df396/2/– Sergio