views:

314

answers:

1

I'm trying to modify a name-related element. I'm taking values from a drop-down and displaying them in a div. Their ids are: selected_terms selected_terms_div

I have a number of these pairs and I was hoping to write generalized code instead of hard-coding it (I figure it'll be useful later).

This code isn't working:

$("#" + $(this).attr('id') + "_div")

Thanks in advance!

Edit: Whole script:

$(document).ready(function(){
    $("select").change(function () {
          var str = "";
          $("#selected_terms option:selected").each(function () {
                str += $(this).text() + '<br>';
              });

          $("#" + $(this).attr('id') + "_div").html(str);
    })    
        .change();
});

Note: It works if I change that line to:

$("#selected_terms_div").html(str);
+1  A: 

It started working. You guys were right. It seems right because it is. Thanks for responding.

Stephane