Run function in current element by get short code inside

Posted by happi on Stack Overflow See other posts from Stack Overflow or by happi
Published on 2013-11-02T03:52:14Z Indexed on 2013/11/02 3:53 UTC
Read the original article Hit count: 100

Filed under:
|

In stead of adding an ID (IdAddMore) to run script inside ID(widget1) like that :

<div class="widget" id="widget1">
    <div class="content">
          <div id="IdAddMore"></div>
          <script type='text/javascript'>
          $("#IdAddMore").selectme({
           Numpost:3,
           Postyle : "Enter your style",
           });
          </script>
    </div>
</div>

(widget is added automatically when I add more new widget, It means I can have widget3, widget10, ....Index(3,10..) is any and is not sorted.)

Widget is a HTML/JS widget.

I want run selectme by short code instead of repeating script in each widget.

<div class="widget" id="widget1">
    <div class="content">
        [3][mystyle]
    </div>
</div>
<div class="widget" id="widget50">
    <div class="content">
       [4][yourstyle]
    </div>
</div>
...........

How can I write only script to catch short code in current element is added :

I write script below but it does not work. Check for me, thanks your help.

 <script type='text/javascript'>
var getdata = document.getElementsByClassName(".content").innerText || document.getElementById(".content").textContent;
var thevalue = [];
getdata.replace(/\[(.*?)\]/g, function(g0,g1){thevalue.push(g1);});

$(".widget").selectme({
Numpost:thevalue[0],
Postyle: ""+thevalue[1]+"",
});
</script>

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery