Search code examples
jqueryconflict

Jquery conflict between two functions


I have two functions, which both hide different form elements, the problem is they seem to be conflicting with one another.

I have add a no conflict line to my code, but I am new to Jquery and not sure if I am going about this correctly.

Please find below my code.

 $.noConflict();
 $(function(){     
 $('RadioGroup1').click(function(){
 if ($(this).attr("id") == "realtime")
 {
  $('#total2').show();
 } else {
  $("#total2").hide();
 }
 });
 });


 $(document).ready(function() {
 $('#contact-location').change(function(){
    var location = $(this).val(),
    div = $('#' + location);

    $('div').hide();
        div.show();

});
});

Solution

  • I suppose "RadioGroup1" is the name of your radio buttons.

    Then, your first event handler should be defined like this :

    $('[name=RadioGroup1]').click(function(){
     if (this.id === "realtime") {
       $('#total2').show();
      } else {
       $("#total2").hide();
      }
    });