jQuery Selectors Reference

Forsta HX Platform - API Scripting Guide

jQuery Selectors Reference

ℹ️ Note: For checking option selection, prefer Forsta API methods like f('Qid').item('code').toBoolean(). Use jQuery selectors only when you need to access DOM elements directly.

Common jQuery Selectors:

// Get question element (always use quotes)
f('AQ1')                              // Question AQ1
f('BQ2').find('input')                // All inputs in BQ2
f('CQ3').find('input[type="radio"]')  // Radio buttons only

// Find checked/selected (DOM level)
f('AQ1').find(':checked')             // Checked radios/checkboxes
f('BQ2').find('option:selected')      // Selected dropdown option

// By value
f('AQ1').find('[value="1"]')          // Input with value="1"
f('BQ2').find('input[value!="99"]')   // NOT value 99

// By attribute
f('AQ1').find('[data-custom]')        // Has data-custom attribute
f('BQ2').find('[required]')           // Required fields

// Relationships
f('AQ1').next()                       // Next element after AQ1
f('BQ2').prev()                       // Previous element before BQ2
f('CQ3').parent()                     // Parent element
f('DQ4').siblings()                   // All siblings

// Filtering
f('AQ1').find('input').first()        // First input
f('BQ2').find('input').last()         // Last input
f('CQ3').find('input').eq(2)          // Third input (0-indexed)
f('DQ4').find('input:visible')        // Only visible inputs

Practical Selector Examples:

// Get all checked checkbox labels
var labels = f('BQ1').find('input:checked')
    .map(function() {
        return $(this).next('label').text();
    }).get();

// Count selected items using Forsta API (Recommended)
var count = 0;
f('BQ2').domainValues().forEach(function(code) {
    if (f('BQ2').item(code).toBoolean()) count++;
});

// Check if specific option is selected - Forsta API (Recommended)
var isOptionSelected = f('AQ1').item('2').toBoolean();

// Find all empty required fields (jQuery)
var emptyRequired = $('input[required]').filter(function() {
    return !$(this).val();
});