Skip to content

This class is designed to work like jQuery when creating and working with html elements.

Notifications You must be signed in to change notification settings

mcdanci/HTML-Class-For-PHP

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

This class is designed to work like jQuery when creating and working with html elements. Look at html.class.php to see a list of all the available methods.

A few examples

<?php 
		
	// Get the class
	include 'html.class.php';
	
	// Create a div and set an attribute
	$div = new html('div', array(
		'class' => 'text field'
		));
		
	// Create a label and input
	$label = new html('label', array(
		'for' => 'title',
		'text' => 'Title'
		));
		
	$input = new html('input', array(
		'id' => 'title',
		'name' => 'title',
		'value' => 'My Awesome Site'
		));
		
	// Append the label and the input
	$div->append($label, $input);
	
	// Or chain the methods
	$div->append($label)
		->append($input);
		
	// Or append the elements to the div
	$label->appendTo($div);
	$input->appendTo($div);
	
	// Or clone the div before appending stuff
	// This was designed for loops
	$tmp_div = $div->_clone()->append($label, $input);
	
	// Put the div on the page,
	// and destory the temporary div
	echo $tmp_div;
	unset($tmp_div);
	
	
	// Whoops, we forgot to add our heading
	$heading = new html('h3', array(
		'text' => 'Title Field',
		'class' => 'field-heading'
		));
	
	// Ah, that's better
	$div->prepend($heading);
	
	// Or
	$heading->prependTo($div);
	
	// Put the div on the page
	echo $div;
?>

About

This class is designed to work like jQuery when creating and working with html elements.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 100.0%