0

I use this script in a Website with jquery 1.7.

$('input:radio[name=article-info]:!checked').parent().parent().removeClass('highlight')

I move this script in a bootstrap template but the chrome console report me this error:

Uncaught Error: Syntax error, unrecognized expression: input:radio[name=article-info]:!checked

Bootstrap use a update version of jQuery .

What should I use syntax for this version?

The complete code:

// Select input radio button
        $('input[type=radio][name=article-info]').change(function() {

               $('input:radio[name=article-info]:not(:checked)').parent().parent().removeClass('highlight');
               $(this).parent().parent().addClass('highlight');

               // Price
               $price = $('label[for="'+ $(this).attr('id') +'"] .tr-price').text();
               $('#price-total').text($price);

               // Url btn
               $new_url = $(this).parent().siblings('.format').children().children('input').val();
               $('#btn-personalizar').attr("href", $new_url);
         });
//Select tr
        $(".data-click-tr").click(function(){


               $(".data-click-tr").removeClass('highlight')
               $(this).addClass('highlight').find('input:radio[name=article-info]').attr('checked', true);

               $get_input_id = $(this).find('input:radio[name=article-info]').val();

               // Precio
               $price = $('label[for="'+ $get_input_id +'"] .tr-price').text();
               $('#price-total').text($price);

               // Url btn personalizar
               $new_url = $(this).find('.format').children().children('input').val();
               $('#btn-personalizar').attr("href", $new_url);
         });

The HTML:

<table id="select-size">
    <thead class="size-and-price">
        <tr class="header-table">
            <th colspan="2">Tamaño</th>
            <th class="">Precio</th>
        </tr>
    </thead>
    <tbody>
        <tr class="data-click-tr highlight" data-click-tr="1426">
            <td class="input">
                <input id="1426" type="radio" name="article-info" value="1426" checked="checked">
            </td>
            <td class="format">
                <label for="">720X1080 mm <a href="//localhost:3000/manta-polar-75x100/1426">(ver ficha)</a>
                <input class="url-designs" type="hidden" value="//localhost:3000/modelos/manta-polar-75x100/1426">
                </label>
            </td>
            <td class="price">
                <label for="1426">
                <span class="tr-price"> 39&nbsp;€</span>
                </label>
            </td>
        </tr>
        <tr class="data-click-tr" data-click-tr="6685">
            <td class="input">
                <input id="6685" type="radio" name="article-info" value="6685">
            </td>
            <td class="format">
                <label for="">950X1400 mm <a href="//localhost:3000/manta-polar-95x140/6685">(ver ficha)</a>
                <input class="url-designs" type="hidden" value="//localhost:3000/modelos/manta-polar-95x140/6685">
                </label>
            </td>
            <td class="price">
                <label for="6685">
                <span class="tr-price"> 49&nbsp;€</span>
                </label>
            </td>
        </tr>
        <tr class="data-click-tr" data-click-tr="710">
            <td class="input">
                <input id="710" type="radio" name="article-info" value="710">
            </td>
            <td class="format">
                <label for="">1200X1900 mm <a href="//localhost:3000/manta-polar-120x190/710">(ver ficha)</a>
                <input class="url-designs" type="hidden" value="//localhost:3000/modelos/manta-polar-120x190/710">
                </label>
            </td>
            <td class="price">
                <label for="710">
                <span class="tr-price"> 69&nbsp;€</span>
                </label>
            </td>
        </tr>
        <tr class="data-click-tr" data-click-tr="2259">
            <td class="input">
                <input id="2259" type="radio" name="article-info" value="2259">
            </td>
            <td class="format">
                <label for="">2400X1600 mm <a href="//localhost:3000/manta-polar-160x240-queen/2259">(ver ficha)</a>
                <input class="url-designs" type="hidden" value="//localhost:3000/modelos/manta-polar-160x240-queen/2259">
                </label>
            </td>
            <td class="price">
                <label for="2259">
                <span class="tr-price"> 89&nbsp;€</span>
                </label>
            </td>
        </tr>
    </tbody>
</table>

This is a Screenshot: enter image description here

2 Answers 2

5

The ! operator cannot be used in the selectors.

You can use :not() selector to invert the selector.

$(':radio[name="article-info"]:not(:checked)')...
                              ^^^^^^^^^^^^^^

The :not(:checked) part in the selector will select the radio buttons which are unchecked.

Sign up to request clarification or add additional context in comments.

5 Comments

Mmm this not report any error in console but not detect the not checked inputs...
@FunnyFrontend This works!. You might be missing something else.
@FunnyFrontend That Works The same code in the question. Saying again, there must be something else that might be causing the problem
aaahhh, I edit the main post twice, You can see the //Select tr script, this fails!
I accept your answer, but Can you help with with the //Select tr?
1

To add a negative control, you must use :not()

 $('input:radio[name=article-info]:not(:checked)').parent().parent().removeClass('highlight')

1 Comment

This must work, but maybe the .parent().parent().removeClass() section is wrong. I don't know what HTML you have for this.

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.