jQuery this function

$('.delivery_option').click(function() {     var current = $('.active-radio-label');     if (current.length)         current.removeClass('active-radio-label');     $(this).addClass('active-radio-label');      $(this).('.delivery_option span').addClass('checked'); }); 

I have a problem with the last line $(this).('.delivery_option span').addClass('checked');

I am trying to point to the span that is in .delivery_option class. After someone click .delivery_option

HTML:

    <div class="delivery_options">   <div class="delivery_option item">     <div>       <table class="resume table table-bordered resp_table ">         <tbody>           <tr>             <td class="delivery_option_radio">               <div class="radio" id="uniform-delivery_option_1349_0"><span><input type="radio" value="199," data-id_address="1349" data-key="199," name="delivery_option[1349]" class="delivery_option_radio" id="delivery_option_1349_0"></span></div>             </td>             <td class="delivery_option_logo">               <img alt="Odbiór osobisty" src="/img/s/199.jpg" class="order_carrier_logo">             </td>             <td class="white_space_normal">               <strong>Odbiór osobisty</strong>               <br>&nbsp;- sklep Konstantynów Łódzki             </td>             <td class="delivery_option_price">               <div class="delivery_option_price">                 Za darmo!               </div>             </td>           </tr>         </tbody>       </table>     </div>   </div>   <!-- end delivery_option -->   <div class="delivery_option alternate_item">     <div>       <table class="resume table table-bordered resp_table ">         <tbody>           <tr>             <td class="delivery_option_radio">               <div class="radio" id="uniform-delivery_option_1349_1"><span class="checked"><input type="radio" checked="checked" value="205," data-id_address="1349" data-key="205," name="delivery_option[1349]" class="delivery_option_radio" id="delivery_option_1349_1"></span></div>             </td>             <td class="delivery_option_logo">               <img alt="Inpost / DPD" src="/img/s/205.jpg" class="order_carrier_logo">             </td>             <td class="white_space_normal">               <strong>Inpost / DPD</strong>               <br>&nbsp;- przelew             </td>             <td class="delivery_option_price">               <div class="delivery_option_price">                 16,00 zł (brutto) </div>             </td>           </tr>         </tbody>       </table>     </div>   </div>   <!-- end delivery_option -->   <div class="delivery_option item">     <div>       <table class="resume table table-bordered resp_table ">         <tbody>           <tr>             <td class="delivery_option_radio">               <div class="radio" id="uniform-delivery_option_1349_2"><span><input type="radio" value="206," data-id_address="1349" data-key="206," name="delivery_option[1349]" class="delivery_option_radio" id="delivery_option_1349_2"></span></div>             </td>             <td class="delivery_option_logo">               <img alt="Inpost / DPD" src="/img/s/206.jpg" class="order_carrier_logo">             </td>             <td class="white_space_normal">               <strong>Inpost / DPD</strong>               <br>&nbsp;- za pobraniem             </td>             <td class="delivery_option_price">               <div class="delivery_option_price">                 27,00 zł (brutto) </div>             </td>           </tr>         </tbody>       </table>     </div>   </div>   <!-- end delivery_option --> </div> 

Replay

You just need

$(this).find('span').addClass('checked');

You need to use .find() to target the span element and then add class.

$(this).find('span').addClass('checked');

I think you need

$('.delivery_option').click(function() {
    var current = $('.active-radio-label');
    if (current.length){
       current.removeClass('active-radio-label')
            .find('sapn') //Find span descendant
            .removeClass('checked'); //remove class
    }

    $(this).addClass('active-radio-label').find('span').addClass('checked');
});

Try this code , it will work

    jQuery('.delivery_option').click(function() {
        var current = jQuery('.active-radio-label');
        if (current.length)
            current.removeClass('active-radio-label');
        jQuerythis).addClass('active-radio-label');

        jQuery(this).('.delivery_option span').addClass('checked');
    });

I made this below it seems to work but it dont make input clicked. It olny change the class. Maybe i shpuld use .click(); on input ?

    <script>
$('.delivery_option').click(function() {
    var current = $('.active-radio-label');
    if (current.length)
        current.removeClass('active-radio-label');
    $(this).addClass('active-radio-label');

    $('.delivery_option').find("span").removeClass('checked')

    $(this).find("span").addClass('checked');
});
</script>

Category: jquery Time: 2016-07-29 Views: 0
Tags: jquery

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

processed in 0.305 (s). 12 q(s)