Wordpress multi-click feature

I would like to use dynamic content on my pages from WordPress; I would like to change the text of a YouTube video. Both functions work fine, but I cannot get both of them to work

Text function (switchcontent.js)

jQuery(document).ready(function($) {
    $("a").click(function(){
        $('#tekst').text( $(this).attr('data-name'));
    });
});
      

Run codeHide result


YouTube function (video.js)

jQuery(document).ready(function($){
	$('.vid_button').click( function(e){
		e.preventDefault();
		var URL = $(this).attr('href');
		//var htm = '[embed]https://youtu.be/' + URL + '[/embed]';
		var htm = '<iframe width="560" height="315" src="http://www.youtube.com/embed/' + URL + '?wmode=transparent&rel=0&theme=dark&color=red&autoplay=1" frameborder="0" allowfullscreen ></iframe>';
		$('.video_position_size').html(htm);
		return false;
	});
});
      

Run codeHide result


Function.php

add_action( 'wp_enqueue_scripts', 'add_my_script' );
function add_my_script() {
	wp_enqueue_script(
        'your-script', // name your script so that you can attach other scripts and de-register, etc.
        get_template_directory_uri() . '/js/custom/video.js', // this is the location of your script file
        array('jquery') // this array lists the scripts upon which your script depends
    );
    wp_enqueue_script(
        'your-script', // name your script so that you can attach other scripts and de-register, etc.
        get_template_directory_uri() . '/js/custom/switchcontent.js', // this is the location of your script file
        array('jquery') // this array lists the scripts upon which your script depends
    );
}
      

Run codeHide result


+3
javascript jquery php


source to share


No one has answered this question yet

Check out similar questions:

6493
var functionName = function () {} vs function functionName () {}
2644
Is there a function "exists" for jQuery?
2414
Why shouldn't I use the mysql_ * functions in PHP?
2329
How do I detect a click outside of an element?
2256
Set default parameter value for JavaScript function
2038
Is there a standard function for testing null, undefined, or empty variables in JavaScript?
1966
How can I select an element with multiple classes in jQuery?
1387
startsWith () and endsWith () functions in PHP
1198
Pure JavaScript jQuery $ .ready () equivalent - how to call a function when the page / DOM is ready for it
923
jQuery multiple events to trigger the same function



All Articles
Loading...
X
Show
Funny
Dev
Pics