How can I improve the readability of my code? It currently has multiple if statements and repetitive sections. The main variation involves insertBefore, prependTo, and some changes in CSS properties. Any suggestions on simplifying this code would be greatly appreciated. Thank you!
if($element.closest('div').hasClass('links')){
$(document.createElement('img'))
.attr({src:'inc/images/bubble_anim.gif', 'class': 'helpImg'})
.insertBefore($element)
.css({'position':'absolute',
'z-index':99,
'top': topPos+30,
'left': leftPos
})
return true;
}
if($element.attr('id')=='option'){
$(document.createElement('img'))
.attr({src:'inc/images/bubble_anim.gif', 'class': 'helpImg'})
.prependTo($element)
.css({ 'z-index':99 })
return true;
}
//if the element is a td element, using propendTo method.
if($element.is('td')){
$(document.createElement('img'))
.attr({src:'inc/images/bubble_anim.gif', 'class': 'helpImg'})
.prependTo($element)
.css({'position':'absolute',
'z-index':99,
'top': topPos,
'left': leftPos
})
return true;
}
//regular elements...
$(document.createElement('img'))
.attr({src:'inc/images/bubble_anim.gif', 'class': 'helpImg'})
.insertBefore($element)
.css({'position':'absolute',
'z-index':99,
'top': topPos,
'left': leftPos
})