jQuery attribute to ID

Hello Experts,

Can anyone tell me why I am getting "[object Object]" instead of e.g. #hrefAttribute".
Basically i am trying to get the "href" attribute and convert it to an ID selection in the jQuery.

$("#news-menu a").click(function(event) {
		event.preventDefault();
		var textSection = $(this).attr('href');
		var textTarget = 	$('#'+textSection+'');		
		console.log (textTarget);
	});

Open in new window

RefaelAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

leakim971PluritechnicianCommented:
$("#news-menu a").click(function(event) {
		event.preventDefault();
		var textSection = $(this).attr('href');
		var textTarget = 	$('#'+textSection+''); // this return a JQuery Object : "[object Object]" 
var textTarget = 	$('#'+textSection+'').html(); // try this OR
var textTarget = 	$('#'+textSection+'').text(); // this
		console.log (textTarget);
	});

Open in new window

0
RefaelAuthor Commented:
Hi leakim971

I do not get it right using the html or text conversion.
Yet i have tried removing the "$" and it looks like it works!?

var textTarget = 	('#'+textSection+'');	

Open in new window

0
leakim971PluritechnicianCommented:
var textSection = "xyz";
var textTarget = 	'#'+textSection; // string, selector
alert(   $(textTarget).text()  ); // will alert "hello world"

Open in new window



<div id="xyz">hello world</div>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RefaelAuthor Commented:
Thank you! Now it is clear. So by removing the "$" I could get the string and pass the ID.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.