Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

there will be 14 similar functions and i need to combine it because those functions interact with each other, help me pls

$(".mieszkanie").click(function() {
        var num = this.id.replace(/c_07_/, "").substr(0, 3);
        $('.pdf').attr({ 
            href: "img/rzuty/mieszkania/pietro07rzuty/" + num + ".pdf"
        });
        $('.karta img').attr({ 
            src: "img/rzuty/mieszkania/pietro07rzuty/" + num + ".png",
            alt: "mieszkanie" + num
        });
    });

$(".mieszkanie").click(function() {
        var num = this.id.replace(/c_10_/, "").substr(0, 3);
        $('.pdf').attr({ 
            href: "img/rzuty/mieszkania/pietro10rzuty/" + num + ".pdf"
        });
        $('.karta img').attr({ 
            src: "img/rzuty/mieszkania/pietro10rzuty/" + num + ".png",
            alt: "mieszkanie" + num
        });
    });

HTML

<div id="div10p" class="okno clearfix rzutyWraper">
        <h2>RZUT 10 PIĘTRA</h2> 
        <div id="rzuty10p" class="rzuty">
            <span id="c_10_248" class="mieszkanie" title=""></span>
            <span id="c_10_247" class="mieszkanie" title=""></span>
            <span id="c_10_249" class="mieszkanie" title=""></span>
            <span id="c_10_250" class="mieszkanie" title=""></span>
            <span id="c_10_252" class="mieszkanie" title=""></span>
            <span id="c_10_251a" class="mieszkanie" title=""></span>
            <span id="c_10_251b" class="mieszkanie" title=""></span>
        </div>      
        <div class="karta">
            <div class="kartaPanel">
                <button class="close">zamknij</button>
                <a class="pdf" href="" onclick="this.target='_blank'">pobierz</a>
            </div>
            <img src="" alt="mieszkanie" />
        </div>
    </div>


    <!-- PIETRO 07 -->
    <div id="div07p" class="okno clearfix rzutyWraper">
        <h2>RZUT 7 PIĘTRA</h2> 
        <div id="rzuty07p" class="rzuty">
            <span id="c_07_001" class="mieszkanie" title=""></span>
            <span id="c_07_002a" class="mieszkanie" title=""></span>
            <span id="c_07_002b" class="mieszkanie" title=""></span>
            <span id="c_07_003" class="mieszkanie" title=""></span>
            <span id="c_07_004" class="mieszkanie" title=""></span>
            <span id="c_07_005" class="mieszkanie" title=""></span>
            <span id="c_07_006a" class="mieszkanie" title=""></span>
            <span id="c_07_006b" class="mieszkanie" title=""></span>
            <span id="c_07_008" class="mieszkanie" title=""></span>
        </div>      
        <div class="karta">
            <div class="kartaPanel">
                <button class="close">zamknij</button>
                <a class="pdf" href="" onclick="this.target='_blank'">pobierz</a>
            </div>
            <img src="" alt="mieszkanie" />
        </div>
    </div>
share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

based on Abuduba code i wrote an final answer

$(".mieszkanie").click(function() {
        var nums =  /._(\d+)_(.+)/.exec( this.id );
            var num2 = nums[2].substr(0, 3);
        $('.pdf').attr({ 
            href: "img/rzuty/mieszkania/pietro"+nums[1]+"rzuty/" + num2 + ".pdf"
        });
        $('.karta img').attr({ 
            src: "img/rzuty/mieszkania/pietro"+nums[1]+"rzuty/" + num2 + ".png",
            alt: "mieszkanie " + num2
        });
    });
share|improve this answer
1  
If you have found your answer please mark it as accepted. –  user555 Nov 13 '12 at 19:08
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.