JQuery issue. Click - open code

I have this JQuery code

jQuery(\'.tpcoupon-reveal\').click( function() {
jQuery(\'.inner-code\').css(\'background-color\',\'#FFF\');
jQuery(\'.inner-code\').text(jQuery(this).attr(\'caption\'));
visitstore = jQuery(this).attr(\'url\');
window.open(visitstore);
    });

$newText = '

            <div class="tpcoupon-code-wrapper">
                <span class="tpcoupon-msg"> '.tpbox2_unhtmlentities($content).'</span>
                <span class="tpcoupon-reveal" caption="'.$couponcode.'" url="'.$url.'">Vis koden & bes√łg siden</span>
                <span class="tpcoupon-code-show">
                    <span class="inner-code"></span>
                </span>
            </div>
            <div class="clr"></div>
';

Due to this code when I click on span object with id tpcoupon-reveal it shows me code in span object with id inner-code The problem is that I have many blocks in one page. But when I click one span it opens all codes in all span with id=inner-code How to make JQuery to open only this block?

Answers


Try scoping the jQuery seletor for '.inner-code' by doing this inside the click handler:

$(this).parent().find('.inner-code')

Need Your Help

Regex match of apostrophe in autohotkey script

html regex escaping autohotkey apostrophe

I have an autohotkey script which looks up a word in a bilingual dictionary when I double click any word on a webpage. If I click on something like "l'homme" the l' is copied into the clipboard as ...

Preventing overlays from disappearing when zoomed - MKMapView & MKOverlay

iphone mkmapview overlay tiles

I am working on an iPhone / iPad app that is using semi-transparant tiled map overlays via MKMapView and MKOverlay.

Is a plain-text password in a CGI script a security hole?

perl security cgi webserver cgi-bin

I've read that things can go wrong with your web server which may lead to display of PHP scripts as plain text files in a web browser; consequently I've moved most of my PHP scripts to a directory