slj90 Posted November 10, 2015 Share Posted November 10, 2015 Trying to combine 2 vars and use them as an ID.. var x = "#inputList"; var y = 2; $(add_button).click(function(e){ e.preventDefault(); alert([x+y]); $([x+y]).css('display', 'inline'); y = y + 1; The alert displays #inputList2 but the line below doesn't work. Any ideas?Thanks Quote Link to comment https://forums.phpfreaks.com/topic/299427-combine-2-variables-and-use-as-an-id/ Share on other sites More sharing options...
requinix Posted November 10, 2015 Share Posted November 10, 2015 x+y is "#inputList2". A string. [x+y] is ["#inputList2"]. An array. I don't know where you're getting those []s from but get rid of them. Quote Link to comment https://forums.phpfreaks.com/topic/299427-combine-2-variables-and-use-as-an-id/#findComment-1526154 Share on other sites More sharing options...
chriscloyd Posted November 12, 2015 Share Posted November 12, 2015 var x = "#inputList", y = 2; $(add_button).on('click', function(e) { e.preventDefault(); $(x + y).css('display','inline); console.log($(x + y)); //this should show you if you have the right object check your console y++; return false; }); Quote Link to comment https://forums.phpfreaks.com/topic/299427-combine-2-variables-and-use-as-an-id/#findComment-1526288 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.