Handling Html-Attributes with Ajax

Since Html5 and the intensive use of data attributes, I would like to focus on some important points and describe the best-way.

Set an attribute Ajax

While using this attribSet method the value(if exists) will be overwritten

Factory::getResponseInstance()->attribSet('htmlElementId','my-attribute', 'attribute-value string');

jybrid-javascript setAttribute (regular)

// setting an attribute 

Will be set an Attribute with key("my-attribute-name") an value ="string"

<input id="element-id" my-attribute-name="string"/>

Set an property

Usually properties are used in form elements such as disabled""multiple""checked" and so on. In html these properties can be without value in the tag. <input name="test" disabled/> in Xhtml, "disabled" must be provided with a visible value <input name="test" disabled="disabled"/>

Factory::getResponseInstance()->attribSet('htmlElementId','my-attribute', true);

jybrid-javascript setAttribute (as property)

// setting an property 

Will set an Property without an visible Value "my-attribute-name" indicates with his presence that the attribute/property was set!

<input id="element-id" my-attribute-name/>

Append Attribute

Add a string value to an existing or non-existent attribute, for example, as in styles or data attributes. Make sure you response an leading space " myAppendString" if need.

Factory::getResponseInstance()->attribAppend('htmlElementId','my-attribute', 'attribute-value append string');

jybrid-javascript attribAppend (as property)

// adding an attribute value
jybrid.attribAppend('element-id|Element','my-attribute-name','attribute-value append string')

Will be add an Attribute with key("my-attribute-name") an value ="existing-string" " myAddString"

<input id="element-id" my-attribute-name="existing-string myAddString"/>

Remove an attribute or property


or with Php-Boolean value false removes the attribute also

Factory::getResponseInstance()->attribSet('htmlElementId','my-attribute', false);

jybrid.hasAttrib (javascript only)

// returns bool!

demo ajax attribute manipulation

@see simple schematic schematic-ajax-attributes.php

further reading ajax examples

@see simple schematic schematic-attributes.php