Getting data with .attr / .data

Googled this and cant understand why it isnt working… I’m just trying to grab the data-* value … I’ve tried both data & attr :confused:

html…

       <label class="cb-post-label" for="label2" data-toggle="#post-c">Hide Post</label>
       <span class="cb-position"><input type="checkbox" checked="checked" name="label2" id="label2"/></span>

jq…

    $("input").on("ifChanged", function(event){
    var e = $(this).closest("label").attr("data-toggle");

    if(e != undefined) {
        $(e).hide();
    }
});

The label isn’t a parent of the input. You’d need something like this.

var e = $(this).closest('.cb-position').prev("label").data("toggle");

Balls… Didnt know it had to be a direct ancestor… I’ve written stuff the long way now

Thanks anyway Paul… when/if I get time, I’ll prob go back and change it

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.