- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Learning to include jquery in simple xml
Hi to all, i'm just learning to usi a little of custom jquery in splunk simple dashboard.
I have this at begining of my xml:
<form script="script.js" stylesheet="dark.css">
in script.js i have this:
require([
'jquery',
'splunkjs/mvc/simplexml/ready!'
], function($) {
$(document).ready(function() {
$( "#row1" ).addClass( "red" );
});
});
just a stupid code to see if it's works, but it does not.
Of cource in .css i have the class red. Even if i run in the chrome console:$( "#row1" ).addClass( "red" );
nothing happens.
Could you please help me?
Thanks and regards.
- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I tried to get a function to run on page load, making use of the code you have shown:
$(document).ready(function() {
console.log("page opened");
});
I just could not get that event to trigger on page load (I did a bump and refreshed the page). I finally tried:
$(function(){ console.log("page opened"); });
and this worked. No idea why, in my mind these two are equivalent.
- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks to all. It works, but it seems that i need a splunkweb restart every time i modify a css or js, is it normal?
Thanks and regards
- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

No, a restart isn't necessary every time. If you use the link @kurdbahr provided in the second part of his answer, it creates a new cache for JavaScript and CSS files and then you can just refresh the page.
http://your_splunk_server/en-US/_bump
- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

@renjujacob88 it is actually http://<splunkURLPort>/en-US/debug/refresh
. For Development or Non-prod instances, _bump
, debug refresh
or Development mode
settings are recommended.
Following is the URL to turn on Development Mode settings with no caching: https://docs.splunk.com/Documentation/Splunk/latest/AdvancedDev/CustomVizTutorial#Development_mode_s...
| makeresults | eval message= "Happy Splunking!!!"
- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

As @justinatpnnl pointed out, your Javascript is probably not included in the web page because the Splunk server has not yet noticed your new Javascript file.
To make a new Javascript file available without a full server restart:
$SPLUNK_HOME/bin/splunk restartss
To force a reload of a changed Javascript file:
http(s)://localhost:8000/en-US/_bump
and click the button there to increment the version number.
- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

Your sample code does work, so my guess is that your script isn't being seen by Splunk and isn't loading. View the page source to see if Splunk was able to find it and load it into your dashboard.
The CSS should appear in the head
tag:
<head>
...
<link rel="stylesheet" type="text/css" media="all" href="/en-US/static/@264376:0/app/search/dark.css" />
...
</head>
The JavaScript should be at the bottom of the page just before the closing of the body
tag:
<script src="/en-US/static/@264376:0/app/search/script.js" type="text/javascript"></script>
</body>
Usually in order to get my new scripts and css files to populate in a dashboard I need to restart Splunk.
