Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery loop with wildcard
    primarykey
    data
    text
    <p><a href="http://jsfiddle.net/8KJTn/" rel="nofollow">FIDDLE</a></p> <p>I'm having some html markup with uls. Whenever the user clicks on a link with the class vid_* (* as something) the ul with that id should be shown. When I use loops without wildcards, the following works:</p> <pre><code>$(".vid_all").click(function () { $("#vid_bla").addClass("hidden").removeClass("visible"); $("#vid_muh").addClass("hidden").removeClass("visible"); $("#vid_tschub").addClass("hidden").removeClass("visible"); }); $(".vid_bla").click(function () { $("#vid_bla").addClass("visible").removeClass("hidden"); $("#vid_muh").addClass("hidden").removeClass("visible"); $("#vid_tschub").addClass("hidden").removeClass("visible"); }); $(".vid_muh").click(function () { $("#vid_muh").addClass("visible").removeClass("hidden"); $("#vid_bla").addClass("hidden").removeClass("visible"); $("#vid_tschub").addClass("hidden").removeClass("visible"); }); $(".vid_tschub").click(function () { $("#vid_tschub").addClass("visible").removeClass("hidden"); $("#vid_bla").addClass("hidden").removeClass("visible"); $("#vid_muh").addClass("hidden").removeClass("visible"); }); </code></pre> <p>Now I want to use wildcards instead in order to handle the loops dynamically and shorten it a bit.</p> <p>I tried the following but it is not working:</p> <pre><code>var vidRnd = /(.vid_*)/; var arrVidId = new Array("#vid_plattform", "#vid_format", "#vid_bro"); for (var k in vidRnd) { $(k).click(function() { for (var i in arrVidId) { $(i).addClass("hidden").removeClass("visible"); } $(k).addClass("visible").removeClass("hidden"); }); }; </code></pre> <p>I want to use wildcards for the array too but I dont know how to. Any ideas on this?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload