HTML:
<div class="someclass" rel="first">text 1</div>
<div class="someclass" rel="second">text 2</div></div></div>
<div class="info_ly">here is some text</div>
<div class="first" > the first DIV </div>
<div class="second" > the second DIV </div>
CSS:
.first{ display:none}
.second{ display:none}
Jquery:
$(".someclass").click(function() {
$(".info_ly").html($(this).attr('rel'));
});
I want to call and load the “rel” DIV inside “info_ly” DIV.
With this Jquery code I get only text “first” or “second” inside “info_ly” DIV.
How can I load the DIV with the class “first” or DIV with the class “second” inside “info_ly” DIV?
Like this:
You can view a demo here, if the other divs had IDs though, it gets a bit simpler, e.g.
rel="#first", or making the clickable elements anchors withhref="#first"would be even better.Here’s an example of the alternative approach I mentioned using anchors:
And your jQuery narrows down to this:
This has the added benefit of degrading gracefully when JS isn’t enabled (as well as being bookmarkable if you add just a bit of code), you can see a demo of this approach here.