We help IT Professionals succeed at work.

Set Unordered List attributes in page_load

slimguy
slimguy asked
on
I need to dynamically set the img src attributes of an unordered list in the page_load event.
How can I do this please in the sample list below?

        <div class="CarouSlide s3">
              <ul class="slider-holder">
                    <li id="no1c">
                          <img src="images/dashboard.jpg" width="50" height="50" />
                    </li>
                    <li id="no2c">
                          <img src="images/CO2a.jpg" width="50" height="50" />
                    </li>
                    <li id="no3c">
                          <img src="images/health.jpg" width="50" height="50" />
                    </li>
              </ul>
</div>
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008
Commented:
Since you have an HTML element, instead of server control, you could 1) add an "id" and runat="server" element, and reference the control, or 2) use JavaScript in <body> onLoad handler.
CERTIFIED EXPERT

Commented:
why not use JQuery? Why page_load event?
CERTIFIED EXPERT

Commented:
$("img").attr({  
  src: "/images/dashboard.jpg", 
  title: "Dashboard", 
  alt: "Dashboard alt" 
}); 

Open in new window

CERTIFIED EXPERT

Commented:
    $(".slider-holder li").("img").attr({  
  src: "/images/dashboard.jpg", 
  title: "Dashboard", 
  alt: "Dashboard alt" 
}); 

Open in new window


or

    $(".slider-holder #no1c").("img").attr({  
  src: "/images/dashboard.jpg", 
  title: "Dashboard", 
  alt: "Dashboard alt" 
}); 

Open in new window

Author

Commented:
Thanks, that was the hint I needed!
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008

Commented:
I like the JQuery examples, too.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.