I have two divs side by side. The left (methods) div contains links which, when clicked, load some text into the right (descriptions) div from an external html file using '.load'. I also have some script to match the height of the 'methods' div to the 'descriptions' div, which I have placed into a function.
My problem is that I can't get the height-matching function to run on the same click as the text-loading script. At the moment, clicking a link loads the text as I want, but the height-matching doesn't happen until a link is clicked again.
I am new to javascript/jQuery so open to any and all resolutions including total rewrites of the code if that's what it takes.
Code can be seen "functioning" here: http://plnkr.co/edit/1CW1a7XNu73Kyo4xPMyg?p=preview
$(document).ready(function() {
function matchDesc() {
var hh = document.getElementById("descriptions").offsetHeight;
document.getElementById("methods").style.height = hh + "px";
}
$("#content").on('click', '#link', function(){
var str = $(this).attr('class');
var sect = str.slice(-1);
$("#descriptions").load("descriptions.html #description-" + sect);
$("#methods li a").css('color','#3164BE');
$(this).css('color','red');
matchDesc();
});
window.onload = function() {
matchDesc();
}
});
load()...$("#descriptions").load("descriptions.html #description-" + sect, function() { matchDesc(); });.. it is because theloadmethod is asyncronous and the actual content is loaded after the call tomatchDesc