Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript jquery effect not working

  • This topic is empty.
Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #150918
    asma
    Participant

    why my p tag is not toggleing in second div(container2).i put the same p tag and button tag in the second div but why its jquery effect not working as it works perfectly in first div. here is mo code. http://jsfiddle.net/SeEGj/

    #150925
    whatsoever
    Participant

    IDs are supposed to be unique. To make your code work, just use something like this.

    $(document).ready(function(){
      $("button").click(function(evt){
        $('p', evt.target.parentNode).toggle();
      });
    });
    
    #150930
    asma
    Participant

    can u plz write a code pen? i would give a better idea.

    #150931
    whatsoever
    Participant

    Here you go, you could have just changed the javascript in your fiddle tho :)

    http://jsfiddle.net/kux3K/1/

    #150936
    asma
    Participant

    if i use id or class of an element instead of button it did’nt work. how is it done with elements id or class instead of just using direct tag name like button here? i have 5 list items each with an ID when hover over each list item an image slides with it. its working perfectly fine but when i copy pasted this same list in the same page jquery does’nt work and the image dont move.

    #150938
    whatsoever
    Participant

    You cannot expect jQuery to work when using IDs for selectors and have more than one element with the same ID. Provide a live example of the page so we could give you some hints :)

    #150959
    asma
    Participant

    here is my code:
    http://jsfiddle.net/xJF6Y/
    jquery only works in container div, but same thing is not working in container2 div.

    #150967
    whatsoever
    Participant

    The values of ID attributes are supposed to be unique. This code will work.
    http://jsfiddle.net/4GsnM/1/

    Please take your time to read this:
    http://www.w3.org/TR/REC-html40/struct/global.html#h-7.5.2

    #150976
    asma
    Participant

    thanku so much whatsoever. :)

Viewing 9 posts - 1 through 9 (of 9 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.