Click here to Skip to main content
15,887,453 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
C#
<ul id="FirstList @nIndex" style="display: block;">
                                    <li>
                                        <a class="tree clientName" href="java<!-- no -->script:toggle('SecondList @nIndex)"><img src="images/icon-rr.png" />@clientID</a>
                                        <ul id="SecondList @nIndex">
                                            <li>
                                                <a class="tree" href="java<!-- no -->script:toggle('ThirdList @nIndex')"><img class="paddingr" src="images/icon-rating.png" />Rating</a>

                                                @* Loop for binding the Rate Code  *@

                                                @for (int j = nIndex; j < Model.Clients.ClientTree.Count; j++, nIndex++)
                                                {
                                                    if (clientID == Model.Clients.ClientTree[j].ClientID)
                                                    {

                                                        <ul id="ThirdList @nIndex" style="display:none;">
                                                            <li>
                                                                <a class="tree " href="java<!-- no -->script:toggle('FourthList @nIndex')"><img class="paddingee" src="images/icon-trolly.png" />@Model.Clients.ClientTree[nIndex].RateCode <span>(</span>@description <span>)</span></a>
                                                                <ul id="FourthList @nIndex" style="display:none;">
                                                                    <li>
                                                                        <a class="tree " href="#"><img class="paddinltl" src="images/icon-carriers.png" />LTL Carriers</a>
                                                                        <ul id="FivethList @nIndex" style="display:none;">

                                                                            @* Loop for binding the LTL Carriers  *@

                                                                            @for (int k = 0; k < Model.Clients.CarrierLTLTree.Count; k++)
                                                                            {
                                                                                var currentLTLCarier = Model.Clients.CarrierLTLTree[k];
                                                                                if (clientID == currentLTLCarier.ClientID)
                                                                                {
                                                                                    var dateFormat = new System.Globalization.DateTimeFormatInfo();

                                                                                    var effectiveDate = currentLTLCarier.EffectiveDate.ToString("MM/dd/yyyy");
                                                                                    <li>
                                                                                        <a class="tree ltlCarrier" href="#"><img class="paddinltlCarrier" src="images/icon-rr.png" />@currentLTLCarier.Scac <span>(</span>@effectiveDate <span>)</span></a>

                                                                                    </li>
                                                                                }
                                                                                else
                                                                                {

                                                                                }
                                                                            }

                                                                        </ul>

                                                                    </li>

                                                                    <li>
                                                                        <a class="tree" href="#"><img class="paddinltl" src="images/icon-carriers.png" />TL Carriers</a>
                                                                        <ul id="SixthList @nIndex" style="display:none;">

                                                                            @* Loop for binding the TL Carriers  *@

                                                                            @for (int k = 0; k < Model.Clients.CarrierTLTree.Count; k++)
                                                                            {
                                                                                var currentTLCarier = Model.Clients.CarrierTLTree[k];
                                                                                if (clientID == currentTLCarier.ClientID)
                                                                                {
                                                                                    var effectiveDate = currentTLCarier.EffectiveDate.ToString("MM/dd/yyyy");
                                                                                    <li>
                                                                                        <a class="tree" href="#"><img class="paddinltlCarrier" src="images/icon-rr.png" />@currentTLCarier.Scac <span>(</span>@effectiveDate <span>)</span></a>

                                                                                    </li>
                                                                                }
                                                                                else
                                                                                {

                                                                                }
                                                                            }

                                                                        </ul>
                                                                    </li>
                                                                </ul>
                                                            </li>
                                                        </ul>

                                                    }
                                                    else
                                                    {
                                                        nIndex--;
                                                        break;
                                                    }

                                                }
                                            </li>

                                        </ul>
                                    </li>
                                </ul>

My query is how get anchor text in though jquery
Posted
Updated 5-Feb-14 0:02am
v2
Comments
Pete O'Hanlon 5-Feb-14 5:31am    
What anchor text? You need to encode your HTML when you submit it so that HTML tags are properly represented.
Sampath Lokuge 5-Feb-14 6:04am    
Anchor tag or what ?
akrati shakya 5-Feb-14 6:53am    
Actually this is a treeview and I want the text of parent to child through Jquery
joshrduncan2012 5-Feb-14 9:12am    
You need to reply to a comment instead of creating a new comment otherwise the people who responded will never be notified of your messages.

1 solution

Well, your question is unclear, but it seems that you are looking for a way to traverse a treeview control to get a breadcrumb-style representation of a selected tree node.

Try this fiddle: http://jsfiddle.net/Wc46w/[^]

Here's the jQuery algorithm that recursively collects all the anchor text:
C#
$(function() {
    var breadCrumb = getAnchorText($('.selected'));

    $('.results').text(breadCrumb);

    function getAnchorText(item) {
        var result = '';
        var parentUL = item.parent().parent();

        if (parentUL.parent().length == 1) {
            var parentAnchor = parentUL.prev('a');

            if (parentAnchor.length == 1) {
                result = getAnchorText(parentAnchor) + ' -> ';
            }
        }
        result += item.text();

        return result;
    }
});
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900