JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://cdn.jsdelivr.net/particle-api-js/5.2.6/particle.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<button type="button" id="postfunctionbtn" functionname="manual" functionargs="1,on">Manual</button>
JavaScript
document.getElementById("postfunctionbtn").addEventListener ("click", functionPost, false);
function functionPost(functionName, functionArgument){
console.log(this.getAttribute("functionname"));
console.log(this.getAttribute("functionargs"));
var fnPr = particle.callFunction({ deviceId, functionName, functionArgument, token});
fnPr.then(
function(data) {
console.log('Function called succesfully:', data);
}, function(err) {
console.log('An error occurred:', err);
});
}
var deviceID = '35002400094734343xxxxxx';
var token = '3aaacdf9121d404c1a60d5f5f8535xxxxxxx';
var particle = new Particle();