0
Ich möchte id
ein Element, dessen Auswahl entspricht der href
eines <a>
Elementein Element, dessen Select ID entspricht href Attribut jQuery
HTML
<a href="web"></a>
<a href="app"></a>
<div id="web"></div>
<div id="app"></div>
jQuery
$('a').on('click', function(e) {
e.preventDefault();
var $href = $(this).attr('href');
var $id = $('div').attr('id');
$(this).addClass('active');
//HERE I WANT TO SELECT THE DIV WHOSE "id" MATCHES THE "href" of the <a> clicked
$('div').id($href).addClass('active');
});
Das war's! Die Sache ist, was $ ('#' + $ href) tut? – tavozapata
'$ ('#' + $ href)' wählt das div aus, dessen ID mit dem cliked '' '' 'href' übereinstimmt. @ tavozapata – Azim
Oh ich sehe, ich hätte nie gedacht, dass das Zusatzzeichen würde das tun – tavozapata