2
votes

I am trying to retrieve the first two characters of a link's title attribute, store it into a variable, and then call that variable as a function. In the code, where it says "#" + s, is where I want that value to be placed. Any ideas?

$(".flow").click(function() {
    if (labelstatus = 1) {
        $('.rmflow a,.weflow a,.scflow a,.coflow a,.wcflow a').css({
            color: "#b7b7b7"
        });

        $("." + this.title + " a").css({
            color: "#3e3e3e"
        });

        $("#" + this.title).parent().animate({
            opacity: '1'
        });

        $('.initiate').animate({
            opacity: '.4'
        }, 100);

        // variable to be put in the below selector
        $("#" + s).parent().animate({
            opacity: '1'
        });

        $('.info').fadeOut(200);
        $("#" + this.title).fadeIn(1000);
        return false;
    }
    else {
    }
});
2

2 Answers

20
votes

get the first 2 characters in the title: var s = $(this).attr("title").substr(0, 2);

2
votes

Get first two of attribute and find target based on it.

$('.flow').click(function() {
    var first2 = $(this).attr('customatt').substr(0, 2);
    $('#' + first2).doSomething();
    return false;
});