How Do I Change Menu Link Text Within a href and li With jquery?
I would like to know how to change/rename the word "Snapshot" with a new word "Home". Does anyone know what "jquery" code will accomplish this? I have been struggling with this for days and finally had to ask for some help. Snapshot is located 7th lines down from the beginning of the code below. Full code would be appreciated but if not, just a direction to point me in would really help!
The words in BOLD are the ones needing the change/replacement:
href="/admin/snapshot">Snapshot
Changed/Replace to:
href="/admin/snapshot">Home
<div id="main">
<div id="nav-col">
<div id="nav">
<ul>
<li>
<a href="/admin/snapshot">Snapshot</a> </li>
<li>
<a href="/admin/offers">Offers</a> <ul>
<li>
<a href="/admin/offers">Manage Offers</a> </li> <li>
<a href="/admin/offers/add">Create Offer</a> </li> <li>
<a href="/admin/shared_offers">Offer Exchange</a> </li> <li>
<a href="/admin/offer_files">Creative Files</a> </li> <li>
<a href="/admin/offer_access/applications">Offer Applications</a> </li> <li>
<a href="/admin/offer_types">Offer Categories</a> </li> <li>
<a href="/admin/offer_groups">Offer Groups</a> </li> <li>
<a href="/admin/customer_lists">Customer Lists</a> </li> </ul>
</li>
<li>
<a href="/admin/stats">Reports</a> <ul>
<li>
<a href="/admin/stats/index/daily">Daily Report</a> </li> <li>
<a href="/admin/stats/index/hourly">Hourly Report</a> </li> <li>
<a href="/admin/stats/index/affiliates">Affiliates Report</a> </li> <li>
<a href="/admin/stats/index/advertisers">Advertisers Report</a> </li> <li>
<a href="/admin/stats/index/offers">Offers Report</a> </li> <li>
<a href="/admin/stats/index/ad_campaign">Ad Campaigns Report</a> </li> <li>
<a href="/admin/stats/conversion_report">Conversion Report</a> </li> <li>
<a href="/admin/stats/affiliate_referral_report">Affiliate Commission</a> </li> <li>
<a href="/admin/stats/commission_report">Manager Commission</a> </li> <li>
<a href="/admin/stats/mod_summary_logs">Server Logs</a> </li> </ul>
</li>
<li>
<a href="/admin/affiliates">Affiliates</a> <ul>
<li>
<a href="/admin/affiliates">Manage Affiliates</a> </li> <li>
<a href="/admin/affiliates/pending">Pending Affiliates</a> </li> <li>
<a href="/admin/affiliates/create">Create Affiliate</a> </li> <li>
<a href="/admin/offer_pixels">Conversion Pixels / URLs</a> </l开发者_运维问答i> <li>
<a href="/admin/offer_disabled_links">Disabled Links</a> </li> <li>
<a href="/admin/users/index/affiliate">Manage Users</a> </li> <li>
<a href="/admin/affiliates/referral_list">Referral List</a> </li> <li>
<a href="/admin/affiliate_tiers">Payout Tiers</a> </li> <li>
<a href="/admin/billing/affiliate_billing">Affiliate Billing</a> </li> <li>
<a href="/admin/billing/invoices">Billing Invoices</a> </li> <li>
<a href="/admin/billing/receipts">Billing Payments</a> </li> </ul>
</li>
<li>
<a href="/admin/advertisers">Advertisers</a> <ul>
<li>
<a href="/admin/advertisers">Manage Advertisers</a> </li> <li>
<a href="/admin/advertisers/pending">Pending Advertisers</a> </li> <li>
<a href="/admin/advertisers/create">Create Advertiser</a> </li> <li>
<a href="/admin/users/index/advertiser">Manage Users</a> </li> <li>
<a href="/admin/advertiser_billing">Advertiser Billing</a> </li> </ul>
</li>
<li>
<a href="/admin/ad_campaigns">Ad Manager</a> <ul>
<li>
<a href="/admin/ad_campaigns">Manage Campaigns</a> </li> <li>
<a href="/admin/ad_campaigns/add">Create Campaign</a> </li> </ul>
</li>
<li>
<a href="/admin/company/account">Company</a> <ul>
<li>
<a href="/admin/company/account">My Account</a> </li> <li>
<a href="/admin/employees">Manage Employees</a> </li> <li>
<a href="/admin/alerts">Notifications</a> </li> <li>
<a href="/admin/customize">Customize Application</a> </li> </ul>
</li>
<li>
<a href="/admin/support">Support</a> <ul>
<li>
<a href="/admin/support">Help</a> </li> <li>
<a href="/admin/support/api">API</a> </li> <li>
<a href="/services-agreement.html">Terms of Service</a> </li> <li>
<a href="/admin/company/upgrade">Upgrade</a> </li> </ul>
</li>
</ul>
</ul>
</div>
</div>
Here you go:
$('a[href="/admin/snapshot"]').text('Home');
http://jsfiddle.net/xfRYh/
It would be tedious to do these one by one (if that is the ultimate intention), but if you have the new values stored in a sorted array then you might be able to get away with something like this:
$.each($('li a'), function(index, item) {
$(this).text(arrayOfStrings[index]);
});
精彩评论