wildcard in js?

Collapse
X
 
  • Time
  • Show
Clear All
new posts

  • gits
    replied
    Originally posted by hsriat
    Ok, thanks:)

    I got it...
    it is used for the regEx to check from the end of the string ... ;)

    kind regards

    Leave a comment:


  • hsriat
    replied
    Ok, thanks:)

    I got it...

    Leave a comment:


  • hsriat
    replied
    Why is id_suffix + '$' used?

    Leave a comment:


  • gits
    replied
    ok :) to make it 'sure' working:

    [CODE=javascript]function get_nodes_by_cl ass(obj, class_name, id_suffix) {
    var node_list = [];
    var nodes = document.getEle mentsByTagName( obj);
    var re = new RegExp(id_suffi x + '$');

    for (var i = 0, n; n = nodes[i]; i++) {
    if (n.className == class_name && n.id.match(re)) {
    node_list.push( n);
    }
    }

    return node_list;
    }

    // usage
    var hq_divs = get_nodes_by_cl ass('div', 'hq', '_N');[/code]
    kind regards

    Leave a comment:


  • hsriat
    replied
    Thanks, I just made a little change and its working!!
    :)


    [CODE=javascript]function get_nodes_by_cl ass(obj, class_name, id_suffix) {
    var node_list = [];
    var nodes = document.getEle mentsByTagName( obj);

    for (var i = 0, n; n = nodes[i]; i++) {
    if (n.className == class_name && n.id.match(id_s uffix)) {
    node_list.push( n);
    }
    }

    return node_list;
    }

    // usage
    var hq_divs = get_nodes_by_cl ass('div', 'hq', '_N');[/code]

    Leave a comment:


  • gits
    replied
    [CODE=javascript]function get_nodes_by_cl ass(obj, class_name) {
    var node_list = [];
    var nodes = document.getEle mentsByTagName( obj);

    for (var i = 0, n; n = nodes[i]; i++) {
    if (n.className == class_name) {
    node_list.push( n);
    }
    }

    return node_list;
    }

    // usage
    var hq_divs = get_nodes_by_cl ass('div', 'hq');
    [/CODE]
    now simply iterate over the 'hq_divs' and set innerHTML :)

    kind regards

    Leave a comment:


  • hsriat
    started a topic wildcard in js?

    wildcard in js?

    There are few DIVs in my HTML who have ids in the form of randomString+ '_N'

    eg
    [html]<div id="fhgse_N" class="hq"></div>
    <div id="dgf5g_N" class="hq"></div>
    <div id="ns65h_N" class="hq"></div>[/html]

    I need to provide innerHTML to them by splitting the response text string from AJAX.

    Since I don't know what the random strings (prefixed to the IDs) would be, but I know that the suffix is _N, the class name is hq and tag name is div.

    How can I set innerHTML of these DIVs?
    Wildcard could help in that.
Working...