Setting the alt attribute on the node image

2 posts, 0 answers
  1. Jon Shipman
    Jon Shipman avatar
    43 posts
    Member since:
    Nov 2009

    Posted 15 Aug 2012 Link to this post

    I set the ImageURL property of the TreeView Nodes during the NodeDataBound event.  I want to set the text for the "alt" attribute of the image.  If I set the ToolTip property of the Node, it adds the ToolTip text to the alt property of the Node image, but it also adds a "title" property with the same text to the entire text of the node.  This is unwanted.

    So, the question is: How can I set the image alt text on a node, during binding in code, without adding the same text as the title attribute for the text?

    Thanks.
  2. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 20 Aug 2012 Link to this post

    Hello Jon,

    Thank you for contacting Telerik Support team,

    One really easy and convenient approach to achieve this behavior is to use javascript and jQuery. You could use this piece of code:

    <script type="text/javascript">
        var $ = $telerik.$;  
     
        $(document).ready(function () {
         $('.rtImg').each(function () {
      var $img = $(this);
      var filename = $img.attr('src')
      $img.attr('alt', filename.substring(0, filename.lastIndexOf('.')));
                                    });
                            });
    </script>

    Here you can find some detailed information about client-side approach.

    If you have any further questions, don't hesitate do contact us again.

    Regards,
    Boyan Dimitrov
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top