/    Sign up×
Community /Pin to ProfileBookmark

string operations

I need help with the following using javascript or jQuery.

I would like to perform the following operations on a string like the below. There are multiple like this on the page and the main identifier is “ms-gb” class on the td tag.

<tbody id=”titl4909-1_” groupString=”%3B%23BOE%204%2E0%20Shop%20Cost%20Study%3B%23″><tr id=”group0″><td colspan=”100″ nowrap class=”ms-gb”><a href=”javascript:” onclick=”javascript:ExpCollGroup(‘4909-1_‘, ‘img_4909-1_‘,event, false);return false;”><img src=”/_layouts/images/minus.gif” border=”0″ alt=”collapse” id=”img_4909-1_” />&nbsp;L1</a> : My Test File Name<span style=”font-weight: lighter”>&nbsp;&#8206;(3)</span></td></tr></tbody>

1.If the text in between closing anchor tag “</a>” and beginning span tag “<span” is just 3 characters long (that is ” : “), I would like to remove the whole parent tbody tag.

Else, I would like to do the following

  • 2.

    I would like to replace “&nbsp;L1” between image close tag “/>” and anchor close tag “</a>”. The text “&nbsp;L1” is not static and can be different.

  • 3.

    I would like to remove ” : ” which appears after closing anchor tag “</a>”

  • 4.

    I would like to remove the entire span tag.

  • to post a comment
    JavaScript

    2 Comments(s)

    Copy linkTweet thisAlerts:
    @vayumaheshauthorAug 18.2011 — Thanks. I was able to get the solution through jQuery. Here is my code for anyone looking for similar help.

    $j("table.ms-listviewtable td.ms-gb").each(function() {

    var curHtml = $j(this).html();

    var curHtmlImgPos = curHtml.search("&nbsp;");

    var curHtmlAnchorPos = curHtml.search("</A>");

    var curHtmlSpanPos = curHtml.search("<SPAN");

    //Hide category name and colon

    var header1Name = curHtml.slice(curHtmlImgPos, curHtmlAnchorPos);

    curHtml = curHtml.replace(' :','');

    curHtml = curHtml.replace(header1Name,'');

    $j(this).html(curHtml);

    //Hide Category Count

    $j(this).find('span').remove();

    if (curHtmlSpanPos-curHtmlAnchorPos == 7)

    $j(this).parent().parent().remove();

    });
    ×

    Success!

    Help @vayumahesh spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 6.18,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @nearjob,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,
    )...