javascript code is only work in jquery 1.7.2

354
January 12, 2017, at 3:40 PM

I currently use lastest jquery in my bootstrap but my javascript code is not working and lastest jquery. It's only work in jquery 1.7.2 but bootstrap need jquery 1.9.1 at least. What wrong with my code? Which part I need to change ?

Here is my code

$(document).ready(function(){
  $("input:radio[name='highlight']").on('change',function(){
    if ($('#radio7').attr("checked")){
      $("#additional-service").addClass('shadow');
    } else {
      $("#additional-service").removeClass('shadow');
    }
  });
  $("input:radio[name='highlight']").on('change',function(){
    if ($('#radio8').attr("checked")){
      $("#additional-service1").addClass('shadow');
    } else {
      $("#additional-service1").removeClass('shadow');
    }
  });
  $("input:radio[name='highlight']").on('change',function(){
    if ($('#radio9').attr("checked")){
      $("#additional-service2").addClass('shadow');
    } else {
      $("#additional-service2").removeClass('shadow');
    }
  });
});

//]]>

Answer 1

It looks like you're trying to check wether some radio inputs are checked. You can't do that with .attr() with recent jQuery versions, you should use .prop() instead :

$(document).ready(function() {
  $("input:radio[name='highlight']").on('change', function() {
    if ($('#radio7').prop("checked")) {
      $("#additional-service").addClass('shadow');
    } else {
      $("#additional-service").removeClass('shadow');
    }
  });
  $("input:radio[name='highlight']").on('change', function() {
    if ($('#radio8').prop("checked")) {
      $("#additional-service1").addClass('shadow');
    } else {
      $("#additional-service1").removeClass('shadow');
    }
  });
  $("input:radio[name='highlight']").on('change', function() {
    if ($('#radio9').prop("checked")) {
      $("#additional-service2").addClass('shadow');
    } else {
      $("#additional-service2").removeClass('shadow');
    }
  });
});
READ ALSO
CSS classes prefixed with '--' are ignored in Safari

CSS classes prefixed with '--' are ignored in Safari

In my own personal style, I liked adding small helper CSS classes with a command-line-argument-like syntax, such as

249
How to make a input field read-only without affecting to it's CSS in razor mvc?

How to make a input field read-only without affecting to it's CSS in razor mvc?

I have an input field which should not allow the user to editBut when I make it read only it shades and all the applied "CSS" properties disappear

364
Non-rectangular back-ground images

Non-rectangular back-ground images

I saw this PSD of a landing page at Pinterest and I was wondering how I could achieve the same style using css: having a non-rectangular image cutting the one above itIs there any easy way of achieving this?

307
Visual Studio 2015 reinstall: ugly CSS editor, no color picker. Why?

Visual Studio 2015 reinstall: ugly CSS editor, no color picker. Why?

I was forced to reinstall VS 2015 update 3Before reisntall I have this CSS/LESS editor, as I like and working with

429