0

I'm working on a modified slide-js file. There are two divs that fade and hide on hover that have anchors for previous and next.

Very simply if there is only 1 image I am trying to remove them like so:

log("removingNextPrevious");
$("div.information-next").remove();
$("div.information-previous").remove();

The console is logged, there are no errors yet these divs are still in the DOM and visible on screen. Ive changing the back colour but that doesn't work either.

Under what circumstances will elements not be removed from the DOM?

DavidB
  • 2,566
  • 3
  • 33
  • 63
  • 2
    can you show your html code? – Or Duan Jul 19 '13 at 07:53
  • Have you checked this post: http://stackoverflow.com/questions/3090662/jquery-empty-vs-remove – achudars Jul 19 '13 at 07:54
  • 1
    Ive just realised these divs are part of a handlerbars template, so obviously thats gonna have an affect – DavidB Jul 19 '13 at 07:54
  • There is only one 'div.information-next' on the page? – PaoloCargnin Jul 19 '13 at 07:59
  • please check your console panel. you have other jquery error in console. so this method is not work. – Bharat Chodvadiya Jul 19 '13 at 08:08
  • the issue is that im trying to remove the element before its rendered by handlerbars. prob best to modify the template and pass in the count of images – DavidB Jul 19 '13 at 08:16
  • 1
    you could place code after the handlebars .append code, and count the results there, like `var imgcount = $("div.information-next").length; if ( imgcount == 1 ) { ... remove them ... }` , or `if ( $("div.information-next").length == 1 ) { ... remove them ... }` if you like terse code – Dom Day Jul 19 '13 at 08:33
  • Thanks Dom, I just modified the template and passed a boolean in "MoreThanOneImage" works a treat. I didnt notice it was a template as ive just switched to vs2012 and turne3d on dark screen mode – DavidB Jul 19 '13 at 09:18
  • Is that code executed either in a $(document).ready() block, or included in a script tag after those elements in the document? – Bobby Jack Jul 19 '13 at 07:54
  • its done in $(document).ready() bloc ready yes – DavidB Jul 19 '13 at 08:08

1 Answers1

0

Try this code :

$(function() {
    $("div.information-next, div.information-previous").remove();
})
Lucas Willems
  • 6,673
  • 4
  • 28
  • 45