0

I have this code:

<script>
    $(document).ready(function () {
        $(document).on('click', '.a_mod_t', function (e) {
            e.preventDefault();
            var id = $(this).attr('rel');
            var data_d = 'id=' + id;
            $.ajax({
                type: "POST",
                data: data_d,
                cache: false,
                url: "php/show_dec.php",
                success: function (html) {
                    var obj = $.parseJSON(html);
                    $.each(obj, function (index, element) {
                        var id_trattamento = element.id_trattamento; // trattamento, id_tariffa, tip_dente, denti(txt)
                        var id_tariffa = element.id_tariffa;
                        var tip_dente = element.tip_dente;
                        var denti = element.denti;
                        var array = new Array();
                        var array2 = new Array();
                        var var_a = "#";
                        array = denti.split(',');
                        var arrayLength = array.length;
                        for (var i = 0; i < arrayLength; i++) {
                            // put the # inside the array 
                            alert(array2[i]);
                            //Do something
                        }
                        alert(id_trattamento);
                        alert(id_tariffa);
                        alert(tip_dente);
                        alert(array[0]);
                    }); // fine .each
                }, // fine success
                error: function (xhr, status, error) {
                    console.log(status);
                    console.log(error);
                    console.dir(xhr);
                } // fine error
            }); // fine ajax
        });
    });
</script>

In this code I get a string text and then I split it and put it into an array. Everything is fine but I need to do another thing and I don't know how.. this array contains the splitted text so for example I have array[0] that contains the text "61". 61 is also the id of a checkbox that I need to change with jquery. but to do so I need to put a "#" in my array before every text. I need to know how I can obtain this -> array[0] = #61 .. or if there is a way to join the # symbols during the jquery command, something like:

$ '#' . ('array[0]').css(..);
1
  • 1
    Use $('#' + array[0]).css(...) Commented Jul 31, 2015 at 11:17

1 Answer 1

1

Just prepend it to the selector:

$('#' + array[0]).css(..);

Note: Numeric only IDs are only valid HTML for HTML 5 and should be avoided.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.