Search code examples
jquerysharepointtaxonomy

Jquery and get value based on class name


I have one html tag where I would like to get the value

<INPUT id=ctl00_MyTaxonomyFieldID_ctl00_ctl01 class="ms-taxonomy ms-taxonomy-height ms-long" value=MyTaxonomyFieldValue|f0d123d1-ac8c-4a18-bccb-65c9b5ea83af type=hidden>

The result should be like f0d123d1-ac8c-4a18-bccb-65c9b5ea83af

Thanks.


Solution

  • UPDATE[2]:

    To call by full class name use:

    $('.ms-taxonomy.ms-taxonomy-height.ms-long').val().split('|')[1]
    

    To call more than one class name, you must separate them using '.'

    Demo:

    http://jsfiddle.net/ZXRTP/2/

    UPDATE:

    To get it based on class name, use:

    $('.ms-taxonomy').val().split('|')[1]
    

    Where '.ms-taxonomy' is the class name you want to call. To call an ID you must use #IDvalue, to call a class use .CLASSvalue

    Demo:

    http://jsfiddle.net/ZXRTP/1/

    ORIGINAL ANSWER:

    Use "" to open and close yout attributes appropriately.

    <input id="ctl00_MyTaxonomyFieldID_ctl00_ctl01" class="ms-taxonomy ms-taxonomy-height ms-long" value="MyTaxonomyFieldValue|f0d123d1-ac8c-4a18-bccb-65c9b5ea83af" type="hidden">
    

    First we need to understand you rules. If every input valu starts with "MyTaxonomyFieldValue|", then you can use this:

    $('#ctl00_MyTaxonomyFieldID_ctl00_ctl01').val().split('|')[1]
    

    Demo:

    http://jsfiddle.net/ZXRTP/