0

how can I execute 2 functions at the same time. In the code snippet below with the onclick, I get the id of the parent Div and then execute a function using the id,

<div id="selDe">
<input type="radio" class="ger" id="num1" checked><label for="num1">
<input type="radio" class="ger" id="num2"><label for="num2">
</div>
<div id="selRe" >
<input type="radio" class="ger" id="num1" checked><label for="num1">
<input type="radio" class="ger" id="num2"><label for="num2">

JS:

<script>
$(".ger").on({
    click:function(){
        var pid = $(this).parent().attr("id");  //get the name of the div parent
        $("#"+pid+" .ger").on({   
//execute the function, but it just works after the next click
            click: function () {
                var showV = this.id.slice(3);
                alert(showV)
            }
        });
    }
});

7
  • I don't think this is possible in JS Commented May 1, 2013 at 17:17
  • 1
    ID should always be unique....that is why it is called "ID" Commented May 1, 2013 at 17:19
  • 2
    I think you mean "in one click handler," not "at the same time." This is absolutely possible. Commented May 1, 2013 at 17:19
  • Is your question "is it possible to call one function from another"? Or I'm missing some important part? Commented May 1, 2013 at 17:20
  • yeah, I mean in one click handler Commented May 1, 2013 at 17:20

1 Answer 1

1

Try this:

$('div[id^=sel]').on('click', '.ger, div[id^=sel] .ger', function () {
    var pid = $(this).parent().attr("id");
    alert(pid);
    var showV = this.id.slice(3);
    alert(showV);
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.