1

I want to change the image inside class="slide" when its toggled. There are several widgets like this so relevant widget image must be changed.

<div class="widget">
      <h3>Inhaltsverzeichnis</h3>
      <div class="widgetbox">
        <ul>
          <li><a href="#"> Prozessbeschreibung</a></li>
          <li><a href="#">Produkte & Dienstleistung </a></li>
          <li class="active"><a href="#">Beschaffen</a></li>
          <li><a href="#"> Prozess-Steckbrief</a></li>
          <li><a href="#"> Beschreibung</a></li>
          <li><a href="#"> Mitgeltende Dokumente</a></li>
          <li><a href="#"> Korrekturhinweise</a></li>
          <li><a href="#"> Optimierungsvorschläge</a></li>
          <li><a href="#"> Prozessübersicht</a></li>
        </ul>
      </div>
      <div class="slide"><img src="img/slideup.png" width="16" height="15" alt=""/</div>
    </div>

currently Js is

$(".slide").click(function(){
    $(this).prev().children().slideToggle("slow", function() { 

    });
});

now how can i change the img slideup.png to slidedown.png when the ul is hidden , the following works but it replaces all images from all widgets.

  if ($('div.widgetbox>ul').css("display")=="none") {  
      $(".slide>a>img").attr("src", "img/slidedown.png");
  }
  else{ 
      $(".slide>a>img").attr("src", "img/slideup.png");
  }

1 Answer 1

1

You can give id for img tag eg:

<img src="flower.png" id="image"/>

then

$(".slide").click(function(){
    $(this).prev().children().slideToggle("slow", function() { 
       $('#image').attr('src','sample.png');
    });});
Sign up to request clarification or add additional context in comments.

1 Comment

result will be same, it will be repetation of codes to write new new id for every new box

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.